我正在使用 boost::thread 库 (V1.44) 来支持我的 C++ 项目中的线程。
用户需要能够无限期地暂停在其自己的线程中运行的测试循环的执行,并且能够随时恢复它。
在Windows下我这样解决了
bool ContintueLoop(){
if(testLoopPaused){ //testLoopPaused can be set by the user via GUI elements
try{
boost::this_thread::interruptible_wait( 2147483648 ); //that's very ugly,
// somebody knows the right way to pause it for a unlimited time?
return true;
}
catch( boost::thread_interrupted& e ){ //when the user selects resume the
// the thread is interrupted and continues from here
testLoopPaused = false;
return true;
}
if( ... ) //test for other flags like endTestLoop etc.
....
}
这可以毫无问题地工作,即使知道无限中断的正确值会很好。
我开始实现我的程序的 linux 版本,但遇到了编译器错误的问题
错误:
interruptible_wait
不是成员boost::this_thread
问题:什么是暂停 boost::thread 无限时间的好方法(直到用户决定恢复它)
非常感谢你