多线程 - 系统创建的其他线程?

时间:2012-06-15 10:43:01

标签: c++ multithreading gdb pthreads

我将gdb附加到正在运行的进程(我的多线程服务器)。然后我请求info thread并且看到总有+1(或2?)个额外的线程,我没有在我的代码中创建。 我只创建了:

  • 4名工人(必须在cond_wait()
  • 1个信号线程(始终位于sigwait()
  • 1个维护线程(每N秒执行一次,然后cond_wait()状态)
  • 1个使用popen()的线程(执行每N秒,然后cond_wait()状态)
  • 1 main()个帖子(accept()

所以,= 8创建的线程由我创建。但为什么报道9或10 ???

系统是FreeBSD 6.4

此外,这个额外的线程总是有问题,它会导致我的程序崩溃,它始终处于pthread_testcancel ()状态! c++ pthreads - crash while trying to lock mutex for reading

似乎是由*标记为10号线的当前执行线程?和8线程相同???或者我有2个额外的线程?这是正常的吗?谢谢..抱歉我的英语不好。

(gdb) info thread
* 10 LWP 100108  0x4865a79b in pthread_testcancel () from /lib/libpthread.so.2 ( WHAT IS ??? (1) )
  9 Thread 0x80d4000 (runnable)  0x486d7bd3 in accept () from /lib/libc.so.6
  8 Thread 0x80d4a00 (LWP 100090)  0x4865a79b in pthread_testcancel ()
   from /lib/libpthread.so.2 ( WHAT IS??? (2) )
  7 Thread 0x80d4c00 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  6 Thread 0x80d4e00 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  5 Thread 0x868b000 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  4 Thread 0x868b200 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  3 Thread 0x868b400 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  2 Thread 0x868b600 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2
  1 Thread 0x868b800 (sleeping)  0x48651cb6 in pthread_mutexattr_init ()
   from /lib/libpthread.so.2

1 个答案:

答案 0 :(得分:1)

其他线程是第三方库的结果。快速搜索curl,ImageMagick,tinyxml2和pcre的源代码,可以看出curl和ImageMagick有pthread_create()次调用。

关于gdb中的调试:

  • info threads中,*表示正在检查的当前线程。它不表示当前线程正在运行。
  • 在回溯上,in ?? ()可以指示库中没有构建调试信息(-g与gcc)或堆栈已损坏。通常,如果堆栈已损坏,gdb将给出明确的指示。

另外,请务必核对ImageMagick's thread of execution documentation