Multiple producer - multiple consumer with std.concurrency?

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 7 15:06:09 PST 2016


On 12/07/2016 12:08 PM, Christian Köstlin wrote:
 > I really like std.concurrency for message passing style coding.
 >
 > Today I thought about a scenario where I need a multiple producer,
 > multiple consumer pattern.
 > The multiple producer is easily covered by std.concurrency, because
 > all producers just can send to one Tid.
 > The tricky part is the multiple consumer part. At the moment I do not
 > see a way for several Tid's to share the same mailbox. Did I miss
 > something, or how would you implement this paradigm?
 >
 > thanks in advance,
 > christian
 >

The simplest idea is to have a single dispatcher thread that distributes 
to consumers. However, both that and other shared mailbox designs are 
inherently slow due to contention on this single mailbox.

Sean Parent's "Better Code: Concurrency" presentation does talk about 
that topic and tells how "task stealing" is a solution.

There are other concurrency models out there like the Disruptor:

   https://lmax-exchange.github.io/disruptor/

It's a very interesting read but I don't know how it can be done with 
Phobos. It would be awesome if D had that solution.

Ali



More information about the Digitalmars-d-learn mailing list