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

后端 未结 4 1620
一整个雨季
一整个雨季 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 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.

提交回复
热议问题