[dmd-concurrency] shutting down
Michel Fortin
michel.fortin at michelf.com
Thu Jan 21 09:45:09 PST 2010
Le 2010-01-21 à 12:08, Andrei Alexandrescu a écrit :
> I understand your concern, but I also like the following scenario when I'm at the airport:
>
> 1. I start Firefox
>
> 2. There is no wireless available
>
> 3. All my many pages are spinning waiting to load
>
> 4. I close Firefox
>
> It's instant. I want to prevent threads started by arbitrary libraries for various purposes from being able to delay application shutdown indefinitely.
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.
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.
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.
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.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the dmd-concurrency
mailing list