Thread overview | |||||
---|---|---|---|---|---|
|
May 28, 2018 Close Threads | ||||
---|---|---|---|---|
| ||||
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 Re: Close Threads | ||||
---|---|---|---|---|
| ||||
Posted in reply to candle | 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 Re: Close Threads | ||||
---|---|---|---|---|
| ||||
Posted in reply to candle | 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
|
Copyright © 1999-2021 by the D Language Foundation