I'm considering to use C++0x threads in my application instead of Boost threads. However, I'm not sure how to reimplement what I have with standard C++0x threads since they don't seem to have an interrupt()
method.
My current setup is:
- a master thread that manages work;
- several worker threads that carry out master's commands.
Workers call wait()
on at least two different condition variables. Master has a "timed out" state: in this case it tells all workers to stop and give whatever result they got by then. With Boost threads master just uses interrupt_all()
on a thread group, which causes workers to stop waiting. In case they are not waiting at the moment, master also sets a bool
flag which workers check periodically.
However, in C++0x std::thread
I don't see any replacement for interrupt()
. Do I miss something? If not, how can I implement the above scheme so that workers cannot just sleep forever?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…