Subj : Re: concurrent switching between multiple buffers To : comp.programming.threads From : Markus Elfring Date : Mon Sep 26 2005 09:29 pm > 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. (That is, the read thread would read a PRIVATE > buffer of input, and then write the shared "buffer" pointer, signalling > the write thread that input was ready. The write thread, when it > finished a write, would wait for a new input buffer, copy the pointer > and clear the shared pointer, write the data, free the buffer, and wait > for a new input buffer.) With a little more sophistication the write > thread can "recycle" the buffer rather than freeing it and making the > read thread allocate a new one. You can make the read thread add buffers > to a queue so that it can process input as quickly as it comes even if > the write thread gets delayed -- if it queues a second input buffer > while the write thread is working, it'll just catch up later. (Though > there are certainly applications where that model might not be appropriate.) 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 Regards, Markus .