It looks like passing a pointer to an immutable(Message) works
as well:
Oh, yes, pointer. Ha! I didn't even think of that. Thanks.
I'm not familiar with how garbage collection works in D. If the
initial reference goes out of scope, and you just have a pointer
- in another thread, no less - then are you still guaranteed that
the object will not disappear while the pointer exists?
Like if I did something akin to:
// ...like before...
void send_msg(Tid tid, int n)
{
auto msg = new immutable(Message)(n);
send(tid, thisTid(), &msg);
}
void main()
{
Tid tid = spawn(&threadFunc);
send_msg(tid, 100);
receiveOnly!int();
}
Do I know that the message object won't be garbage collected
before the thread finishes with it? (I realize this is a very
artificial example, but something like this could happen in a
bigger library).
Frank