[dmd-concurrency] shutting down

Andrei Alexandrescu andrei at erdani.com
Thu Jan 21 10:15:43 PST 2010


Michel Fortin wrote:
> I think you're trying to fix the problem at the wrong layer. Putting
> restrictions to the shutdown protocol means that people will bypass
> the shutdown protocol (write their own) when it gets in the way, and
> then libraries concerned with properly closing things will each
> implement their own shutdown protocol you'll need to call manually at
> the end of main.

I think putting restrictions on the shutdown protocol means that people 
will make sure their programs end orderly.

> Forcefully closing sockets when the application closes isn't much
> different than calling exit(0), but limited to sockets. In either
> case, it's a major pain to workaround when you really need to do
> something before termination.

Sockets must be closed when main exits. If you want to wait for the 
sockets to timeout, you wait in main. I don't see how that is a 
limitation. It just clarifies the application exit sequence.

> And I'll add that in a GUI application, often it's the GUI that is
> sluggish to terminate itself, taking its time to close windows,
> closing files, closing everything. Only once that's done is the main
> thread terminated, at which point little time remains to be gained.

In a properly designed application, indeed. But sockets timeout is (by 
default) 60 seconds. Nobody would be happy if there was 60 seconds extra 
delay when e.g. restarting their browser.

> 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.
> 
> Perhaps this could work for threads too.

This is an interesting feature, and I can definitely see its motivation 
and its usefulness in Phobos' threads.

Andrei


More information about the dmd-concurrency mailing list