Subj : Re: concurrent switching between multiple buffers To : comp.programming.threads From : David Butenhof Date : Tue Sep 27 2005 02:09 pm Markus Elfring wrote: >> If you'd rather make it parallel, there are many ways to fix the problem >> with more careful design, depending on your actual intentions for the >> real program of which this might serve as a prototype. At the most >> trivial level, for example, you might switch "buffer" to a >> multi-buffering set, or even a queue, so that your read and write >> threads can operate independently on DIFFERENT buffers at the same time, >> and then coordinate. [...] > > Your algorithm description sounds like that a non-blocking (lock-free) technique might > also be applicable. > Example: Document "Asynchronous Data Sharing in Multiprocessor Real-Time Systems Using > Process Consensus" by Jing Chen and Alan Burns > http://citeseer.ist.psu.edu/114960.html > http://www.carrara.ch/fachbeitraege/Consensus.pdf Sigh. Lock-free techniques can be great for many things. I think the queuing and flow control of an application analogous to this one would need to be vastly more sophisticated than what's been described to justify the time and effort, however. I also don't think it makes sense to even introduce the concept of lock free design to someone who's just starting out and at the level where mistakes such as those in the OP are made. "Conservation of confusion" applies -- some confusion must be lost before new confusion may be added. ;-) -- Dave Butenhof, David.Butenhof@hp.com HP Utility Pricing software, POSIX thread consultant Manageability Solutions Lab (MSL), Hewlett-Packard Company 110 Spit Brook Road, ZK2/3-Q18, Nashua, NH 03062 .