www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Close Threads

reply candle <fichtknick tuta.io> writes:
Hey Folks.

I have a question about threading and how to close threads i 
don't need anymore.

In the following code, i build 3 threads with spawn from the 
concurrency module.

if one thread found the number, all others thread must stop 
search.

but i have a big logical problem in my mind.

i hope someone can help me to find a solution.

Happy Greetings

and here is the code:
https://pastebin.com/vQRediG6
May 28 2018
next sibling parent candle <fichtknick tuta.io> writes:
sorry about my double post, but:

the receive in the search function, was first under (in) the 
(guess =! searchFor) block, but it was the same effect. for 
testing i have these writeln("test1 and 2").

writeln(guess) i have never seen.

is receive a loop itself ?
May 28 2018
prev sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 05/28/2018 11:47 AM, candle wrote:
 Hey Folks.
 
 I have a question about threading and how to close threads i don't need 
 anymore.
 
 In the following code, i build 3 threads with spawn from the concurrency 
 module.
 
 if one thread found the number, all others thread must stop search.
 
 but i have a big logical problem in my mind.
 
 i hope someone can help me to find a solution.
 
 Happy Greetings
 
 and here is the code:
 https://pastebin.com/vQRediG6
The problem is, the threads are all in their while loops, never checking 'finish' message. You need to move the 'receive(bool finish)' checking inside the while loop but you must replace it with receiveTimeout with 0 duration, otherwise your receive call will block until a message arrives: receiveTimeout(0.msecs, (bool finish) { if(finish == true){ return; } }); Ali
May 28 2018