从这里开始:https ://computing.llnl.gov/tutorials/pthreads/#ConVarSignal
请注意,pthread_cond_wait 例程将在等待时自动且原子地解锁互斥锁。
以下子代码来自同一链接(由我格式化):
pthread_mutex_lock(&count_mutex);
while (count<COUNT_LIMIT)
{
pthread_cond_wait(&count_threshold_cv, &count_mutex);
printf("watch_count(): thread %ld Condition signal received.\n", my_id);
count += 125;
printf("watch_count(): thread %ld count now = %d.\n", my_id, count);
}
pthread_mutex_unlock(&count_mutex);
问题:
当它说pthread_cond_wait
在等待时会自动解锁互斥锁,那么为什么我们必须在上面的代码末尾显式指定函数?pthread_mutex_unlock
我错过了什么?