以下是有问题的帖子的摘录:
pthread_mutex_lock(&(data->mutex));
for(;;)
{
pthread_cleanup_push((void(*)(void *))pthread_mutex_unlock, (void*)&(data->mutex));
while(data->fifo_cnt == 0) pthread_cond_wait(&(data->cond_write), &(data->mutex));
pthread_cleanup_pop(1);
// Do stuff
pthread_mutex_lock(&(data->mutex));
data->fifo_cnt -= write_len;
pthread_cond_signal(&(data->cond_written));
}
pthread_cond_wait的man指出当线程被取消时(等待cond var。),在运行清理处理程序之前会重新获取相关的互斥锁。所以应该有一个解锁这个互斥锁的清理处理程序......
但是当我取消我的帖子时,valgrind报告:
==4094== Thread #10 unlocked a not-locked lock at 0x61ED02C
==4094== at 0x402577B: pthread_mutex_unlock (hg_intercepts.c:610)
==4094== by 0x804CA5D: write_thread (rip.c:60)
==4094== by 0x4028734: mythread_wrapper (hg_intercepts.c:221)
==4094== by 0x404F7AF: start_thread (pthread_create.c:300)
==4094== by 0x41548FD: clone (clone.S:130)
rip.cd:60正好位于pthread_cleanup_push() 这是正确的 - 从这个宏内部调用清理处理程序,但为什么Valgrind认为它已解锁?