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
  • Close Threads candle via Digitalmars-d-learn
    • Re: Close Threads candle via Digitalmars-d-learn
    • Re: Close Threads Ali Çehreli via Digitalmars-d-learn

Reply via email to