Lock-free IPC (seen in DDJ)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Lock-free IPC (seen in DDJ)

Post by Pype.Clicker »

An article i've found in Dr Dobb's Journal: "Lock-free Interprocess Communication". I haven't read it in detail but it sounds appealing.

Just wanted to report it to MT (and see your reaction about it ;) )
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Pype.Clicker »

just got a deeper look and, quite frankly, i'm disappointed. What the guy calls "lock-free IPC" is merely

Code: Select all

do {
   while (shared_memory[i]==0) doSomethingUseful();
   ConsumeWord(shared_memory[i]);
   i++;
}
so yes ... it's lock free ... but it will only do good job if you have actually "something useful" to do and have more CPUs than threads involved into the "chain of communication".
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Colonel Kernel »

I haven't read the article yet, but there is a lock-free implementation of IPC in Singularity. The catch of course is that its safety relies on certain guarantees made by the compiler regarding how IPC channels can be used.

Language Support for Fast and Reliable Message-based Communication in Singularity OS

I'll read the article now... :)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Pype.Clicker »

nice article too, though it doesn't seem to be on the same topic at all, as far as i can tell.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Colonel Kernel »

Exactly. Isn't that why you were disappointed with the DDJ article (because it wasn't about implementing general-purpose IPC in an OS)? :)
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Solar »

Pype.Clicker wrote: ...it will only do good job if you have actually "something useful" to do and have more CPUs than threads involved into the "chain of communication".
But... but... aren't we all going to use 100-CPU multicore systems any day now? :o ;D

(Oh yes, it's so easy to ignore algorithm issues and let the hardware progression solve them... hello Windows. 8) )
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Lock-free IPC (seen in DDJ)

Post by Pype.Clicker »

Colonel Kernel wrote: Exactly. Isn't that why you were disappointed with the DDJ article
no. More because i expected it to present some kind of "new" technique for IPCs and it just appeared to be a old technique you've shown in CS courses to illustrate the need for synchronizing atomic functions in an OS (in order to avoid time wasted in polling loops).
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Lock-free IPC (seen in DDJ)

Post by Candy »

lockfree IPC: use locked bus transactions. They're atomical by nature. Okay, locked bus transactions aren't actually lock-free but at least they don't lock much.

Hm... Thinking of it, lock-free is impossible by definition, except in cases where you use them rather as deferred cothreads. Using an OS that has a yield_to(xyz) function allows that, you allocate space for one item, produce one item and store it, then if it is full, you yield to the consumer(s). Dito for consumers, when it's empty, you yield to the producer. Assuming quick thread switches, this is darn fast.
Post Reply