[dmd-concurrency] priority messages
Andrei Alexandrescu
andrei at erdani.com
Mon Jan 25 08:20:11 PST 2010
Michel Fortin wrote:
> Personally I'd tend to just not define any priority and deal with
> things in a FIFO manner to keep things simple. If you want to add
> complexity (priority), it should be justified by use cases. So which
> use case do you have in mind for priority?
Thread termination! Also forcibly closing any protocol in progress. In
an expanded file copy example that reads and writes several files, a
read error should immediately send the signal to abort writes, even
writes of buffers that are still waiting in the queue.
> About sending exceptions, I see two possibilities: either you
> manually send an exception, or a thread is terminated by an
> exception. In the first case, you'll need the exception to be either
> immutable, shared, or Unique!Exception. In the second case, which
> according to my Thread Termination protocol the exception gets sent
> to the owner thread, the terminating thread can safely cast the
> thread-local exception to Unique!Exception since all other
> thread-local references are lost when the thread terminates.
The problem is, my purpose is not to throw an exception. I want to send
a priority message that will necessarily (a) be processed before
non-priority messages, and (b) that is never ignored by receive().
Exceptions are a mechanism used to do (b).
> About throwing Exceptions in receive... I've been thinking lately and
> I wonder if this couldn't be generalized a bit more, using a
> libdispatch-inspired API. What if instead of receive() having a
> special case for exceptions it had a special case for shared
> delegates and functions? You could then do this:
>
> tid.send({ throw new Exception(); });
>
> The interesting result is that any thread can instantly becomes a
> worker queue.
That is fine as a means to throw exceptions across threads, but I'm
looking for priority messages.
Andrei
More information about the dmd-concurrency
mailing list