我有许多使用 std::condition_variable
的 wait
函数运行事件队列的pthread . 我希望能够将 pthread_cancel
发送到这些工作线程,然后成功 pthread_join
.
但是,我注意到 pthread_join
挂起,整个程序陷入僵局 . 有办法做我想做的事吗?
下面是我的一个工作线程循环的示例(此函数作为 pthread_create
的参数给出):
void* pendingWritesThreadLoop(void* data){
setupThread();
std::unique_lock<std::mutex> lock(pendingWriteQueueMutex);
do{
pendingWriteQueue_cv.wait(lock, []{
return pendingWriteQueue.size();
});
if(pendingWriteQueue.size()){
WritePackage incoming_RequestPackage = pendingWriteQueue.front();
pendingWriteQueue.pop_front();
lock.unlock();
handlePendingWrite(incoming_RequestPackage);
lock.lock();
}//if there's stuff to do
}//do
while(true);
}//pendingWritesThreadLoop
谢谢!