std.concurrency : sending immutable classes
Gary Willoughby
dev at nomad.so
Mon Nov 11 11:18:15 PST 2013
On Monday, 11 November 2013 at 18:54:04 UTC, Dicebot wrote:
> Any ideas? :)
This is one way:
import std.concurrency;
import std.stdio;
shared class A
{
public string toString()
{
return "aaa";
}
}
void thread()
{
for (;;)
{
receive(
(shared A x)
{
writeln(x.toString());
},
(Variant x)
{
writeln(x.type);
writeln(x);
}
);
}
}
void main()
{
auto tid1 = spawn(&thread);
auto val = new shared(A)();
// tid1.send(42);
tid1.send(val);
for (;;) {}
}
I must admit the concurrency confuses me and i need to play with
it more. :)
More information about the Digitalmars-d-learn
mailing list