c++ - How to interrupt a waiting C++0x thread? -


I am considering using C ++ 0x thread in my application instead of Boost thread. However, I'm not sure what to re-evaluate with the standard C ++ 0x thread, because they do not have any interrupt () method.

My current setup is:

  • A master thread that works;
  • Many worker threads that meet the Master's commands.

Worker call wait () at least two different condition variables. The Master's "expired" status is: In this case it asks all workers to stop and by then the results they get are to give them. Boost Threads uses interrupt_all () on the thread group along with the master, which stops waiting for the workers if they are not waiting for the moment, the master also has a bool The flag determines which workers check from time to time.

However, no replacement appears for C ++ 0x std :: thread me interrupt () . Do i miss something If not, how can I apply the above plan so that the workers do not go to sleep forever?

Unfortunately I can not be seen in any other way than using voting, waiting to use Rather than wait a timed and use a variable to say blockage.

  void th (interruptor & interruptor) {try {... while (cnd1.timed_wait (d) == incorrect) {interruptor.check_interruption_point (); } ...} (interrupted charge and amp;) {}}  

The interpreter class will preserve a Boolean variable with Mute X or use nuclear operations if you have two functions Check_interruption_point, which is true of Bowlian if an interrupted / throws. Matter creates thread interpreter variables that will be given related threads at construction time. The master is likely to disrupt all the threads dependent on this blocker at one go. If you want to clearly disrupt one thread at a time, you can definitely create an interpreter for each thread.

Depending on the duration of waiting on time you depend on, so your threads can react quickly as your program requires.


Comments