std.concurrency.send
japplegame
japplegame at gmail.com
Sat May 19 06:26:18 PDT 2012
Multithreading in D confuses me more and more.
import std.concurrency;
import std.stdio;
shared Tid tid;
void main() {
send(cast(Tid)tid, "Hello, World");
}
void worker() {
writeln(receiveOnly!string);
}
shared static this() {
tid = cast(shared)spawn(&worker);
}
I hate these explicit casts. It is impossible sharing anything
between threads without these ugly casts from/to shared. Seems
like something wrong in program design when I'm forced to use
explicit casts. But I don't understand what is it exactly.
For example. I need create mutable object in one thread and send
to another. I don't need to share this object, just create, send
and forget. But I have no idea how make this without using shared
attribute and casting to/from it.
More information about the Digitalmars-d-learn
mailing list