[Issue 3462] Add a clean way to exit a process.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Feb 3 14:23:55 PST 2015
https://issues.dlang.org/show_bug.cgi?id=3462
Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |issues.dlang at jmdavisProg.co
| |m
--- Comment #16 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
Honestly, I think that this sort of thing should be left up to whatever program
wants to attempt it. It's _not_ possible to do in the general case, because
there's no way to tell all running threads to exit cleanly. They could be doing
_anything_, including just sitting forever in while(1) {}. The only way for
them to stop cleanly is to choose to stop cleanly. For that, we could signal
them in some way, and then they could choose to shut down, but that requires
that all threads have a common way of being signalled to shut down and that
they're paying attention to it. And I don't think that that works very well,
even if you assume that all threads are using std.concurrency (which is a big
assumption), because unless the threads specifically handles that exception
being thrown from receive, then who knows what they're going to do. It depends
entirely on what the code looks like. Heck, they could be using std.parallelism
rather than std.concurrency without even using core.thread.Thread directly and
still not be using std.concurrency's receive or receiveOnly.
If a program is written with the idea that each thread can be signalled to shut
down, then it becomes possible to tell all threads to shut down cleanly, but
the code has to be written with that in mind. I don't see how a standard
solution makes any sense for that - especially when you consider the high risk
that folks will misunderstand it and misuse it - especially if its usage is as
simple as exitCleanly() - and that's assuming that we can even do it in the
first place.
So, I say that we should just leave it up to programs to do this themselves.
There is no silver bullet here. And it's not like std.concurrency needs
something baked in to be able to do it in your program either. You can just
create your own message that your receive calls expect which indicates to a
thread that it should shut itself down. Then when you want to shut down, you
signal all threads with that message and let them shut down.
--
More information about the Digitalmars-d-bugs
mailing list