I have a question similar to This one . But I want to implement this in Linux, using ACE framework. What is the way to do this
A little more information would help obtain a better answer:
- Are your worker threads waiting on other events prior to running?
- How do your threads communicate with one another?
- Will you always have the ability to terminate gracefully, or are you anticipating having to force terminate some threads?
The other question you mentioned made a very good point:
Typically, the way that a thread terminates is simply to return from the function that defines the thread. Generally, the main thread signals the worker thread to exit using an event object or a simply an integer or boolean value. If the worker thread is waiting in a WaitForSingleObject, you may need to change it to a WaitForMultipleObjects, where one of the objects is an event. The main thread would call SetEvent and the worker thread would wake up and return.
Depending on what you've setup in ACE, you can use interprocess communication from your main thread to your worker threads to tell them to stop, which they would pickup and handle on their next event check. Alternatively, you can use linux's select
.
Hope this points you in the right direction.