On Wednesday, 21 March 2012 at 03:37:35 UTC, Nathan M. Swan wrote:
After playing around with making a library with uses threads, I
realized it would be nice if there could be multiple
inter-thread mailboxes than just one per thread. That way,
client code and third-party library code don't interfere with
each other.
So this is my proposal: that std.concurrency is modified so
that class MessageBox is public and MessageBoxs be passed
around through other MessageBoxs, or perhaps another class is
devised for this.
I'm not sure of the implications of this, though I know I would
find it very useful by allowing me to write code without
("import core."~someLowLevelModule)
After thinking about this more, this is my proposal for the API.
Backward compatibility is more important here than in other
places because it is documented in TDPL.
Each Tid contains a default MessageQueue accessible by property
messageQueue.
The send/receive functions and their variants operate on the
tid's default messageQueue.
The interface for class MessageQueue:
void send(T...)(T vals);
void prioritySend(T...)(T vals);
void receive(T...)(T ops);
receiveOnlyRet!(T) receiveOnly(T...)(T ops);
bool receiveTimeout(T...)(Duration duration, T ops);
@property void maxSize(size_t size);
@property void onCrowding(OnCrowding oc);
@property void onCrowding(bool function(MessageQueue) doThis);
Hopefully, this won't break any current code, and it will be easy
to implement.