如果没有其他线程使用变量标志,这是确保主线程永远不会错过唤醒信号的安全方法吗?
void *Cancel_master_thread(void *arg)
{
while (1)
{
flag = 0;
pthread_mutex_lock(&cancel_in_progress);
flag = 1;
pthread_cond_wait(&cancel_finished, &cancel_in_progress);
pthread_mutex_unlock(&cancel_in_progress);
}
}
void *Cancel_slave_MB()
{
while (1)
{
while (flag != 1)
{
}
pthread_mutex_lock(&cancel_in_progress);
pthread_cond_signal(&cancel_finished);
pthread_mutex_unlock(&cancel_in_progress);
}
}