November 13, 2022
On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:
> On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:
>
>> I even tried core.stdc.stdlib.exit(-1), it does not work.
>
> Tried
> ```
> import core.runtime;
>    Runtime.terminate();
>    core.stdc.stdlib.exit(-1);
> ```
>
> Still does not work.

I have no idea why it would fail. What about assert(0)?
November 13, 2022
On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:
> On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:
>> On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:
>>
>>> I even tried core.stdc.stdlib.exit(-1), it does not work.
>>
>> Tried
>> ```
>> import core.runtime;
>>    Runtime.terminate();
>>    core.stdc.stdlib.exit(-1);
>> ```
>>
>> Still does not work.
>
> I have no idea why it would fail. What about assert(0)?


I guess these two calls somehow only terminate the calling thread (? this is strange for core.stdc.stdlib.exit), the whole program just hangs after the call, and can only be terminated by `kill -9`.


I have to manually go thru each of the treads and plug in some kind of early exit logic to stop the whole program.


Will try assert(0) later.
November 13, 2022
On Sunday, 13 November 2022 at 22:17:32 UTC, mw wrote:
> On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:
>> On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:
>>> On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:
>>>
>>>> I even tried core.stdc.stdlib.exit(-1), it does not work.
>>>
>>> Tried
>>> ```
>>> import core.runtime;
>>>    Runtime.terminate();
>>>    core.stdc.stdlib.exit(-1);
>>> ```
>>>
>>> Still does not work.
>>
>> I have no idea why it would fail. What about assert(0)?
>
>
> I guess these two calls somehow only terminate the calling thread (? this is strange for core.stdc.stdlib.exit), the whole program just hangs after the call, and can only be terminated by `kill -9`.
>
>
> I have to manually go thru each of the treads and plug in some kind of early exit logic to stop the whole program.
>
>
> Will try assert(0) later.

tried:

```
    core.runtime.Runtime.terminate();
    core.stdc.stdlib.exit(-1);
    assert(0);
    enforce(false);
```

Still not working, not even "Ctrl+C", have to `kill -9` to terminate it.
November 13, 2022
On Sunday, 13 November 2022 at 22:42:45 UTC, mw wrote:
> On Sunday, 13 November 2022 at 22:17:32 UTC, mw wrote:
>> On Sunday, 13 November 2022 at 22:06:09 UTC, Imperatorn wrote:
>>> On Sunday, 13 November 2022 at 21:37:47 UTC, mw wrote:
>>>> On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:
>>>>
>>>>> I even tried core.stdc.stdlib.exit(-1), it does not work.
>>>>
>>>> Tried
>>>> ```
>>>> import core.runtime;
>>>>    Runtime.terminate();
>>>>    core.stdc.stdlib.exit(-1);
>>>> ```
>>>>
>>>> Still does not work.
>>>
>>> I have no idea why it would fail. What about assert(0)?
>>
>>
>> I guess these two calls somehow only terminate the calling thread (? this is strange for core.stdc.stdlib.exit), the whole program just hangs after the call, and can only be terminated by `kill -9`.
>>
>>
>> I have to manually go thru each of the treads and plug in some kind of early exit logic to stop the whole program.
>>
>>
>> Will try assert(0) later.
>
> tried:
>
> ```
>     core.runtime.Runtime.terminate();
>     core.stdc.stdlib.exit(-1);
>     assert(0);
>     enforce(false);
> ```
>
> Still not working, not even "Ctrl+C", have to `kill -9` to terminate it.

Tried put assert(0) at the top:


```
    assert(0);
    enforce(false);
    core.runtime.Runtime.terminate();
    core.stdc.stdlib.exit(-1);
```

Seems cannot even terminate the calling thread, since I got that assertion error thousands of times in the log.

November 13, 2022

On Sunday, 13 November 2022 at 21:16:32 UTC, mw wrote:

>

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.

Just give the threads a killswitch, pass the killswitch method to all of the threads, wait for all the threads to exit, and then return. If this doesn't work, than I don't know what will.

1 2
Next ›   Last »