Hi,
Currently each thread spawned has an associated Tid when using
std.concurrency. When calling receive() this is always the Tid (and
associated messagebox) that you receive from.
This becomes a problem when you spawn several worker threads that send
messages to the main thread since each call to receive must know how to
handle all kind on messages.
For example: the current version of the curl wrapper I'm working on
receives HTTP data from worker threads using receive. The user of this
wrapper can also create his own worker threads that will send data to
the main thread. This means that the curl wrapper must be able to handle
the users worker thread messages.
The GO language has solved this problem with channels. My suggestion is
to allow a thread to create additional Tids that can act just like
channels. Then by adding a receive() call that accepts a Tid as first
argument we can use them as channels.
e.g.
-------------------------------------------------
void run() {
auto channel1 = receiveOnly!Tid();
channel1.send("Hello world);
}
Tid channel1 = Tid();
auto tid1 = spawn(&run);
tid.send(channel1);
// receive only from the specified work on the channel
writeln(channel1.receiveOnly!string());
-------------------------------------------------
This would decouple handling of different worker threads if needed.
This is something I need for the curl wrapper I think. I can create
patch for this if it is something that will be accepted upstream?
/Jonas