Thread overview
Determination of thread status.
Dec 25, 2018
Vitaly
Dec 25, 2018
Neia Neutuladh
Dec 26, 2018
Vitaly
Dec 27, 2018
Bastiaan Veelo
Dec 27, 2018
Vitaly
Dec 30, 2018
Brakeran
Dec 30, 2018
Vitaly
Dec 25, 2018
Bastiaan Veelo
Dec 26, 2018
Vitaly
Dec 26, 2018
Vitaly
December 25, 2018
Hi all.
I can not understand how to track me that the thread has finished work.
eg:

import std.concurrency;
void myThread ()
{
// Do the work
}

void main ()
{
Tid thread = spawn (& myThread);
// It is necessary to check whether the thread has finished its work or is active.
}

Could you tell me how to do this?
December 25, 2018
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.
December 25, 2018
On Tuesday, 25 December 2018 at 14:44:43 UTC, Vitaly wrote:
> Hi all.
> I can not understand how to track me that the thread has finished work.
> eg:
>
> import std.concurrency;
> void myThread ()
> {
> // Do the work
> }
>
> void main ()
> {
> Tid thread = spawn (& myThread);
> // It is necessary to check whether the thread has finished its work or is active.
> }
>
> Could you tell me how to do this?

std.concurrency is a low-level API. You may be looking for a higher level API: std.parallelism. See Task.done(), https://dlang.org/phobos/std_parallelism.html#.Task.done

Bastiaan.
December 26, 2018
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.
December 26, 2018
On Tuesday, 25 December 2018 at 17:12:13 UTC, Bastiaan Veelo wrote:
> std.concurrency is a low-level API. You may be looking for a higher level API: std.parallelism. See Task.done(), https://dlang.org/phobos/std_parallelism.html#.Task.done
>
> Bastiaan.
Thanks for the answer.
I will look at the possibilities of std.parallelism.

December 26, 2018
> std.concurrency is a low-level API. You may be looking for a higher level API: std.parallelism. See Task.done(), https://dlang.org/phobos/std_parallelism.html#.Task.done
>
> Bastiaan.
Maybe I misunderstood, but the capabilities of the std.parallelism module do not allow to exchange messages with the stream, if so, this does not suit me.
Correct me if it is not.


December 27, 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
December 27, 2018
> Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF
Thanks.
At the moment, I implemented it through sending a message, and receiveTimeout receiving, if the response is not received after the timeout expires, then it is considered that the  has terminated. Probably this is not right, but I will try other options.
December 30, 2018
On Thursday, 27 December 2018 at 06:22:31 UTC, Vitaly wrote:
>> Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF
> Thanks.
> At the moment, I implemented it through sending a message, and receiveTimeout receiving, if the response is not received after the timeout expires, then it is considered that the  has terminated. Probably this is not right, but I will try other options.

You could use (core.thread) register() the Tid and then locate() it, if return is 0 then the thread was done. else it is still alive doing something.

December 30, 2018
On Sunday, 30 December 2018 at 08:24:20 UTC, Brakeran wrote:
> On Thursday, 27 December 2018 at 06:22:31 UTC, Vitaly wrote:
>>> Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF
>> Thanks.
>> At the moment, I implemented it through sending a message, and receiveTimeout receiving, if the response is not received after the timeout expires, then it is considered that the  has terminated. Probably this is not right, but I will try other options.
>
> You could use (core.thread) register() the Tid and then locate() it, if return is 0 then the thread was done. else it is still alive doing something.

Thank.
It looks like it really is what you need. In the new year I will check. All happy new year in advance.