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.
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".
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.
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? ;D
(Oh yes, it's so easy to ignore algorithm issues and let the hardware progression solve them... hello Windows. )
Every good solution is obvious once you've found it.
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).
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.