Proper way to exit with specific exit code?

mw mingwu at gmail.com
Sun Nov 13 21:16:32 UTC 2022


On Saturday, 19 September 2020 at 06:11:15 UTC, Jacob Carlborg 
wrote:
> On 2020-09-17 16:58, drathier wrote:
>> What's the proper way to exit with a specific exit code?
>> 
>> I found a bunch of old threads discussing this, making sure 
>> destructors run and the runtime terminates properly, all of 
>> which seemingly concluding that it's sad that there isn't a 
>> way to do this easily, but hopefully things have changed in 
>> the last 5-10 years and I'm just missing the obvious solution.
>
> The proper way is:
>
> int main()
> {
>     return 42;
> }
>
> I highly recommend against trying to terminate the application 
> using `exit` or any other way. Just let the control flow return 
> back to the `main` function.

I'm facing this problem to exit early from a multi threaded 
program for mem profiling purpose:

https://forum.dlang.org/thread/zbdevevgghtdgfryuymh@forum.dlang.org


So what the simplest and reliable way to terminate all threads 
and exit to os?

I even tried core.stdc.stdlib.exit(-1), it does not work.






More information about the Digitalmars-d-learn mailing list