[thread] Double Buffer Example

Hi there, I have some example code for boost::thread that illustrates a common multi-threaded design pattern. It's called Double Buffering which, I believe, is commonly used when a consumer is likely to be much slower processing items than a producer producing them. In this case a message queue is not really needed since a two element queue is as good as n element queue. Just imagine the case when a saving_to_database thread operates at 10MBit per second while a producer thread generates database rows at a 15MBit per second. For this example I decided to create a class binary_semaphore which simulates an event object that can either be set or unset. BTW, wouldn't a semaphore class be a nice addition to boost::thread? The code can be found here: http://pastebin.com/ASJp0t5h The code for the example is here: http://pastebin.com/VchGg8ci I think it would be great idea to add some simple pattern examples in the boost/libs/thread/example folder. Please let me know if there is a bug or potential race condition in the example. Regards, Christian
participants (1)
-
Christian Henning