Safe & Performant Inter-Thread Message Passing
John Colvin
john.loughran.colvin at gmail.com
Tue Feb 18 13:30:41 PST 2014
On Tuesday, 18 February 2014 at 21:05:38 UTC, Nordlöw wrote:
> What's the best solution to communicate between threads in D
> today if I care about
>
> 1. Security & Correctness?
> 2. Performance?
>
> and are these mutually exclusive?
>
> Does Phobos or other library contain lockfree queues?
>
> From what I can see std.concurrent.MessageBox requires
> Mutex-locking. Is this really needed or can it be enhanced to
> support lockfree communication similar to what Boost.Lockfree
> does?
Performance and inter-thread communication is heavily dependant
on the use-case, including the details of memory access patterns
etc. (cache misses can hurt you more than lock overheads ever
will)
Most benchmarks that show amazing lock-free performance scaling
deal with pathological cases. A lot of real-world code can be
plenty fast (or even faster) with message-passing or (sometimes
even) locks.
Security and correctness: message passing wins here, no question.
Data is copied between threads, no possibility of races etc. I
really like std.concurrency for this: very intuitive, easy to use
and pretty fast.
More information about the Digitalmars-d
mailing list