Best choice for messages (std.concurrency)

nsf no.smile.face at gmail.com
Wed Aug 18 13:48:08 PDT 2010


Hi. I'm trying to replicate in D my Go demo app which basically
draws mandelbrot fractal using multiple goroutines. In Go it's
fairly easy to communicate between threads, because the memory model
is C like. D 2.0 on the other hand has this thing "TLS by default".
And I saw simple examples of std.concurrency usage in Andrei's book,
but what about more complex ones.

I have a need to pass some kind of a message to a worker thread.
Let's call it Request. It should contain request data, flag that is
used to interrupt thread if the response isn't needed anymore and
obviously the sender ID. What's the best way to do that?

Something like:
shared struct Request {
    bool discard;
immutable:
    byte[] request_data;
    Tid sender;
}

? Or maybe I don't understand something. How this struct should be
allocated in order to be able to pass it between threads? Or should
I use class instead? I think it's very confusing. Any suggestions?


More information about the Digitalmars-d-learn mailing list