digitalmars.D.learn - Determination of thread status.
- Vitaly (16/16) Dec 25 2018 Hi all.
- Neia Neutuladh (5/5) Dec 25 2018 1. Find the Thread object:
- Vitaly (13/19) Dec 25 2018 Thanks for the answer.
- Bastiaan Veelo (2/22) Dec 26 2018 Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF
- Bastiaan Veelo (5/21) Dec 25 2018 std.concurrency is a low-level API. You may be looking for a
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?
Dec 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.
Dec 25 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.
Dec 25 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:Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAF1. 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.
Dec 26 2018
Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAFThanks. 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.
Dec 26 2018
On Thursday, 27 December 2018 at 06:22:31 UTC, Vitaly wrote: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.Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAFThanks. 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.
Dec 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:Thank. It looks like it really is what you need. In the new year I will check. All happy new year in advance.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.Maybe use spawnLinked()? https://run.dlang.io/is/9xbyAFThanks. 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.
Dec 30 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.
Dec 25 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.
Dec 25 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.
Dec 25 2018