Determination of thread status.

Bastiaan Veelo Bastiaan at Veelo.net
Thu Dec 27 02:16:19 UTC 2018


On Wednesday, 26 December 2018 at 05:43:47 UTC, Vitaly wrote:
> On Tuesday, 25 December 2018 at 17:08:00 UTC, Neia Neutuladh 
> wrote:
>> 1. Find the Thread object:
>>   Tid threadId = spawn(&doStuff);
>>   auto thread = Thread.getAll.filter!(x => x.id == 
>> threadId).front;
>> 2. Check the `isRunning` property.
>>
>> The indirection with spawn() is awkward.
>
> Thanks for the answer.
> I checked.
> Thread.getAll [x] .id is of type ulong, and spawn is of type 
> Tid, moreover, they do not intersect in value either. But even 
> if the program spawns a single thread, Thread.getAll [x] 
> .isRunning returns true after the function terminates. Perhaps 
> you need to wait some time.
> You may have to send a message before exiting the function. 
> Just look at the possibilities of std.parallelism.
> I will gladly try other solutions. I would be grateful for your 
> suggestions.

Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF


More information about the Digitalmars-d-learn mailing list