1

我的问题 gdb 输出:

Program received signal SIGINT, Interrupt. 0x00007ffff7bcb86b in
__lll_lock_wait_private ()    from /lib/x86_64-linux-gnu/libpthread.so.0 (gdb) bt
#0  0x00007ffff7bcb86b in __lll_lock_wait_private ()    from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007ffff7bc8bf7 in _L_lock_21 ()    from /lib/x86_64-linux-gnu/libpthread.so.0
#2  0x00007ffff7bc8a6e in pthread_cond_destroy@@GLIBC_2.3.2 ()    from /lib/x86_64-linux-gnu/libpthread.so.0
#3  0x0000000000400ab5 in control_destroy (mycontrol=0x6020c0) at control.c:20
#4  0x0000000000400f36 in cleanup_structs () at workcrew.c:160
#5  0x0000000000401027 in main () at workcrew.c:201

注意:程序在cygwin下运行成功,但是在ubuntu linux下运行,就死锁了。所有子线程的加入在死锁之前完成。

源代码来自网络:http ://www.ibm.com/developerworks/cn/linux/thread/posix_thread3/thread-3.tar.gz

4

1 回答 1

2

错误在control.c

int control_destroy(data_control *mycontrol) {
  int mystatus;
  if (pthread_cond_destroy(&(mycontrol->cond)))
    return 1;
  if (pthread_cond_destroy(&(mycontrol->cond)))
    return 1;
  mycontrol->active=0;
  return 0;
}

这大概是为了破坏互斥锁和条件变量。但相反,它会破坏条件变量两次。

于 2013-11-01T06:53:14.307 回答