[dmd-concurrency] Shutdown protocol
Sean Kelly
sean at invisibleduck.org
Thu Jan 21 12:28:49 PST 2010
On Jan 21, 2010, at 12:18 PM, Andrei Alexandrescu wrote:
> Sean Kelly wrote:
>> On Jan 21, 2010, at 9:40 AM, Sean Kelly wrote:
>>> All this talk makes me think of a funny feature Apple added to Mac OS X 10.6 (Snow Leopard): Sudden Termination. When you shutdown the computer, the OS literally kills every process having the sudden termination flag set. Applications are free to set and unset this flag as they run. Typically, an application with no document open will set its sudden termination flag. But the flag is not set by default so applications can do proper cleanup.
>> Funny, that sounds a lot like setting the isDaemon flag on threads :-)
>
> That flag says "I don't need to do special cleanup upon exit, just kill me." I think that's different from isDaemon.
Not at all. If a normal application receives a shutdown event it can work for as long as it wants to before actually shutting down. I see this when shutting down Windows and OSX all the time--some editor pops up a "save" dialog and shutdown eventually times out and aborts. This is analogous to the main thread joining all non-daemon threads before terminating the process. Setting the SuddenTermination flag tells the system that the process doesn't require cleanup and/or shouldn't prevent the system from terminating, so it's forcibly killed when shutdown occurs. Similarly, a daemon thread is killed forcibly when C main exits (just like all C threads in Windows and Unix).
What I've never liked about this approach in D is that daemon threads survive beyond the time that module dtors are run, so Weird Things can happen. I'd rather have some way to make each one throw an Error and exit cleanly, but this is really only practical if there's some few system calls that can be made to check a flag and throw--wrapping everything is just impractical. It may be that putting this check in receive() is just the thing, though there should be some option to do things the old way for apps that don't use messaging.
More information about the dmd-concurrency
mailing list