Proper way to exit with specific exit code?
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Sep 18 05:02:21 UTC 2020
On Thu, Sep 17, 2020 at 09:53:07PM -0400, James Blachly via Digitalmars-d-learn wrote:
> I never considered this -- so when I call core.stdc.stdlib : exit,
> none of my destructors get called?
> Presumably also not scope(exit) blocks?
> If this is the case, could we simply add a publically-accessible
> shutdown hook in the runtime?
That's the obvious solution, except that actually implementing it is not
so simple. When you have multiple threads listening for each other
and/or doing work, there is no 100% guaranteed way of cleanly shutting
all of them down at the same time. You can't just clean up the calling
thread and leave the others running, because the other threads might
hold references to your data, etc.. But there's no universal protocol
for shutting down the other threads too -- they could be in a busy loop
with some long-running computation, or they may not be checking for
thread messages, or they could be in a server loop that is designed to
keep running, etc.. It's one of those annoying things that reduce to
the halting problem in the general case.
Unless we adopt some kind of exit protocol that will apply to *all*
threads in *all* D programs, I don't see any way to implement something
that will work in the general case.
If blunt statements had a point, they wouldn't be blunt...
More information about the Digitalmars-d-learn