MyQueue for Producer/Consumer Scenario

Hi,

I’ve written a small queue that allows one to communicate with threads. It is a port of Anthony Williams queue-implementation http://www.justsoftwaresolutions.co.uk/threading/implementing-a-thread-safe-queue-using-condition-variables.html to ROOT. There are two examples on how one can use it, included in the zip-file.

ThreadSingleQueue is creating several threads, that will wait until something is in the queue. Once the producer places something there, the consumers take it from the queue and work on it. When everything is placed in the queue by the producer, the producer will wait until everything is processed by the consumers.

ThreadDoubleQueue is creating several consumers. This time it also creates two queue, an input and outputqueue. So the consumers take whatever is in the input queue, process it and the place it back to the outputqueue. The producers waits until there is something in the outputqueue, take it and fill it with new information and put it back to the inputqueue, to be processed by the consumers.

In Order to be able to tell the producer, that all consumers are done, I had to create a selfmade “Semaphore”, which is named MySemaphore. This “Semaphore” is able to decrement to negative numbers, but doesn’t decrement the count on a wait call.

Best wishes,
Lutz
MyQueue.zip (5.58 KB)