[dmd-concurrency] priority messages

Andrei Alexandrescu andrei at erdani.com
Mon Jan 25 06:42:21 PST 2010


I found a weakness of the priority messaging system. Recall that my plan 
was to do the following: if a message inherits Exception and is not 
explicitly expected in receive(), it causes receive() to throw that very 
message. (There was discussion on whether the right base is 
Exception/Throwable/Error.)

That approach nicely uses an existing mechanism to send out-of-band 
values into the control flow. I really think that's a Good Thing, but I 
realized there's a problem. Actually two.

1. What if I want to send an int with priority? Throwing an int is a 
rather absurd proposition, but sending an int to a thread is a very 
reasonable thing to ask for.

2. Exceptions are class objects, so the whole issue of undue sharing and 
consequently marshaling/unmarshaling across threads comes up.

So I'd like to change the approach. Instead of doing a type-based 
priority system (i.e. certain types are priority messages), let's define 
a per-call based priority system (i.e. if you call prioritySend() 
instead of send() the message has priority).

In this proposed approach, if receive() does not explicitly handle the 
message sent with priority, it will be packaged as an exception 
PriorityMessageException!T, where T is the original type sent. The 
advantage is that the exception will be created and thrown in the 
receiving thread (no need to be careful about cross-thread aliasing of 
the exception object.

Feedback welcome.


Andrei


More information about the dmd-concurrency mailing list