Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a lock-free queue "multiple producers-single consumer" exist for Delphi?

I've found several implementations for single producer-single consumer, but none for multiple producer-single consumer.

Does a lock-free queue for "multiple producers-single consumer" exist for Delphi?

like image 861
Daniele Teti Avatar asked Jul 05 '09 11:07

Daniele Teti


4 Answers

Lock-free queue from the OmniThreadLibrary supports multiple producers. You can use it separately from the threading library (i.e. you can use OtlContainers unit in any other framework).

As the Daniele pointed below, there are two queues in the OmniThreadLibrary. The one in the OtlContainers supports multiple producers and multiple consumers while the "smarter" version in OtlComm (which is just a wrapper for the simpler version) is only single producer/single consumer.

Documentation is still a big problem of the OmniThreadLibrary project :(. Some information on the queue can be found here .

like image 79
gabr Avatar answered Nov 16 '22 22:11

gabr


May be that could be helpful: Interlocked SList functions.

like image 32
Alex Avatar answered Nov 16 '22 22:11

Alex


http://svn.berlios.de/svnroot/repos/dzchart/utilities/dzLib/trunk/lockfree/

@Daniele Teti:

The reader must wait for all writers who still have access to the old queue to exit the Enqueue method. Since the first thing the reader does in the Dequeue method is providing a new queue for new writers which enter Enqueue it should not take long for all writers that have a reference to the old queue to exit Enqueue. But you are right: It is lock free only for the writers but might still require the reader thread to wait for some writers to exit Enqueue.

like image 38
dummzeuch Avatar answered Nov 16 '22 21:11

dummzeuch


For a multiple-producer / single-consumer Queue/FIFO, you can easily make one LockFree using SLIST or a trivial Lock Free LIFO stack. What you do is have a second "private" stack for the consumer (which can also be done as a SLIST for simplicity or any other stack model you choose). The consumer pops items off the private stack. Whenever the private LIFO is exhasted, you do a Flush rather than Pop off the shared concurrent SLIST (grabbing the entire SLIST chain) and then walk the Flushed list in-order pushing items onto the private stack.

That works for single-producer / single-consumer and for multiple-producer / single-consumer.

However, it does not work for multiple-producer / multiple-consumer cases.

like image 2
Adisak Avatar answered Nov 16 '22 20:11

Adisak