我目前正在为 boost 线程开发一个小型包装类,但我并没有真正了解睡眠功能是如何工作的,这就是我到目前为止所得到的:
BaseThread::BaseThread(){
thread = boost::thread();
bIsActive = true;
}
BaseThread::~BaseThread(){
join();
}
void BaseThread::join(){
thread.join();
}
void BaseThread::sleep(uint32 _msecs){
if(bIsActive)
boost::this_thread::sleep(boost::posix_time::milliseconds(_msecs));
}
到目前为止,这就是我实现它的方式,但我真的不明白静态 this_thread::sleep 方法如何知道如果我的线程包装器的多个实例处于活动状态时要休眠哪个线程。这是实施它的正确方法吗?