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

后端 未结 4 1619
一整个雨季
一整个雨季 2021-02-20 01:43

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-

相关标签:
4条回答
  • 2021-02-20 01:54

    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 .

    0 讨论(0)
  • 2021-02-20 02:01

    May be that could be helpful: Interlocked SList functions.

    0 讨论(0)
  • 2021-02-20 02:02

    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.

    0 讨论(0)
  • 2021-02-20 02:15

    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.

    0 讨论(0)
提交回复
热议问题