Multiple producer - multiple consumer with std.concurrency?

Christian Köstlin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 7 23:58:41 PST 2016


Hi Ali,

Thanks for the input, will read about this.
About the slowness. I think it also depends on the situation.
Sure, every message from all producers/consumers has to go through one
MessageBox, but, that is a small critical section, if the work for
producing and consuming takes long enough, the contention is not so
important (for small desktop sized problems). I would still be able to
stress all my cores :)

About a single dispatcher: Why not. But the dispatcher would have to
keep track (manually) of tasks to do and unoccupied workers. While this
is for sure possible, simply sharing the MessageBox would be a great
solutions I think. Looking into std.concurrency, it seems that it should
be possible to provide another spawn function, that takes an additional
MessageBox parameter that is then used for creating the Tid (given that
get and put on MessageBox are threadsafe).

What do you think?

Christian

On 08/12/2016 00:06, Ali Çehreli wrote:
> 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