Thread in detached state?

Ish via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 19 08:40:58 PST 2015


On Friday, 13 November 2015 at 19:45:58 UTC, Ali Çehreli wrote:
> On 11/13/2015 07:35 AM, Ish wrote:
>> [...]
>
> I think the following is the idea:
>
> import std.stdio;
> import core.thread;
>
> extern(C) void rt_moduleTlsDtor();
>
> void threadFunc() {
>     writeln("Worker thread started");
>
>     thread_detachThis();
>
>     scope(exit) rt_moduleTlsDtor();
>
>     foreach (i; 0 .. 3) {
>         Thread.sleep(1.seconds);
>         writeln("Working...");
>     }
>     writeln("Worker terminating");
> }
>
> void main() {
>     writeln("Creating thread in main");
>     auto worker = new Thread(&threadFunc);
>
>     writeln("Starting thread in main");
>     worker.start();
>
>     writeln("main terminating");
> }
>
> The output:
>
> Creating thread in main
> Starting thread in main
> main terminating
> Worker thread started
> Working...
> Working...
> Working...
> Worker terminating
>
> Ali

Does not produce the desired effect. For 380 threads (Linux 
limit) it works, for 381 threads it dies. The program termination 
is exactly same as in 381 threads created using spawn().


More information about the Digitalmars-d-learn mailing list