[dmd-concurrency] priority messages

Michel Fortin michel.fortin at michelf.com
Mon Jan 25 09:56:49 PST 2010


Le 2010-01-25 à 12:31, Andrei Alexandrescu a écrit :

> That's perfect as far as priority messages go, and should be part of the API. Unfortunately, I realized that thread termination is _not_ a priority message - it has "handle me" written all over itself, but not "handle me before anything else".

Depends on the case. If the termination is due to an error condition then you might want it to be handled faster. But obviously, in the case where it isn't an error you want to process it serially.

So if a thread terminates normally, it should send a Terminate to all the threads it owns. If a thread terminates with an exception, it could send Terminate as a priority message instead. Although in that case it should be a special kind of Terminate that get caught as an exception. That exception could be used to perform cleanup work like deleting a partially copied file.

That said, if you were sending a web page to a browser instead of writing to a file, you'd probably want it to abort exactly where the problem is, not before. So it's not universal that you want errors to be propagated faster.

So probably the best thing to do is that thread termination should always send events serially. This behaviour is easier to predict and thus less risky of creating races in the program's logic. If you want to handle errors faster, you can always fast-track messages and bypass sequential order explicitly.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list