Add a clean way to exit a process
Leandro Lucarella
llucax at gmail.com
Sun Nov 1 10:35:36 PST 2009
Sean Kelly, el 1 de noviembre a las 12:23 me escribiste:
> I've thought about doing this before, but I haven't come up with a clean
> way to do it yet. The problem with simply throwing an exception is that
> this would only work in the main thread. To allow other threads to
Yes, I completely ignored MT programs because in that case is usually
a little more tricky to stop everithing in a general way. When you have MT
you're probably stucked with manual termination.
> terminate the process you'd have to forcibly terminate other threads,
> and then running dtors would result in undefined behavior. I'd
> considered sending signals to all threads and having them all throw
> exceptions, but it's illegal to throw an exception from a signal hander,
> and Windows has poor signal support anyway. Sadly, I don't know of
> a better solution than simply calling exit() right now.
I guess something can be hacked using pthread_cancel + pthread_cleanup,
but even if this would be possible I think it's too much complexity for
too little gain (and again, I don't know if Windows as a similar
mechanism).
Anyway, I think the common case for a clean exit() are small script-ish
programs (I came up with this problem porting a small Python script to D),
not big multi-threaded applications. Maybe we can have a simple limited
solution: just add this check to the exit() function in my patch:
assert (!thread_needLock());
or something similar that can tell us if there are any other threads
running.
--
Leandro Lucarella (AKA luca) http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
SATANAS EN COMISARIA
-- Crónica TV
More information about the Digitalmars-d
mailing list