【发布时间】:2011-05-26 10:38:17
【问题描述】:
我正在使用 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 无限时间的好方法(直到用户决定恢复它)
非常感谢
【问题讨论】:
-
没有像
Suspend()这样的命令吗? -
@sad_man,不,没有。有一个 sleep 函数可以将线程挂起一段定义的时间,但我不认为挂起的线程可以在随机时间恢复
标签: c++ multithreading boost boost-thread