Using objects that manage threads via std.concurrency
FG
home at fgda.pl
Tue Feb 12 02:08:45 PST 2013
On 2013-02-12 07:58, monarch_dodra wrote:
> I think I didn't explain myself very well. I have my single "master" thread
> which has a "thread-global" mailbox, but I have 3 different objects that are
> sharing that mailbox.
OK, I finally get what you are saying.
You need to create a mailbox and a unique tid for every Manager (and probably
would have to change Manager into a class). Unfortunately this won't work out of
the box, as for example receiveOnly and friends use only the default mailbox of
the current thread.
struct Manager
{
Tid tid;
MessageBox mbox;
this(string s)
{
this.mbox = new MessageBox
tid = Tid(new Mailbox);
spawn(&worker, s, tid);
}
string get()
{
// you'd have to rewrite receive to use custom mbox
return tid.myReceiveOnly!string();
}
}
More information about the Digitalmars-d-learn
mailing list