【发布时间】:2014-03-10 09:53:05
【问题描述】:
我正在尝试使用 ACE Semaphore 库来实现线程池。它不提供像 Posix 信号量中的 sem_getvalue 这样的任何 API。我需要调试一些行为不符合预期的流程。我可以检查 GDB 中的信号量吗?我正在使用 Centos 作为操作系统。
我使用提供计数 0 和 10 的默认构造函数初始化了两个信号量。我在类中将它们声明为静态,并在 cpp 文件中将其初始化为
DP_Semaphore ThreadPool::availableThreads(10);
DP_Semaphore ThreadPool::availableWork(0);
但是当我使用print 命令在 GDB 中打印信号量时,我得到了类似的输出
(gdb) p this->availableWork
$7 = {
sema = {
semaphore_ = {
sema_ = 0x6fe5a0,
name_ = 0x0
},
removed_ = false
}
}
(gdb) p this->availableThreads
$8 = {
sema = {
semaphore_ = {
sema_ = 0x6fe570,
name_ = 0x0
},
removed_ = false
}
}
这里有什么工具可以帮助我,或者我应该切换到 Posix 线程并重新编写我的所有代码。
编辑:根据@timrau 的要求,调用this->availableWork->dump()的输出
(gdb) p this->availableWork.dump()
[Switching to Thread 0x2aaaae97e940 (LWP 28609)]
The program stopped in another thread while making a function call from GDB.
Evaluation of the expression containing the function
(DP_Semaphore::dump()) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) call this->availableWork.dump()
[Switching to Thread 0x2aaaaf37f940 (LWP 28612)]
The program stopped in another thread while making a function call from GDB.
Evaluation of the expression containing the function
(DP_Semaphore::dump()) will be abandoned.
When the function is done executing, GDB will silently stop.
(gdb) info threads
[New Thread 0x2aaaafd80940 (LWP 28613)]
6 Thread 0x2aaaafd80940 (LWP 28613) 0x00002aaaac10a61e in __lll_lock_wait_private ()
from /lib64/libpthread.so.0
* 5 Thread 0x2aaaaf37f940 (LWP 28612) ThreadPool::fetchWork (this=0x78fef0, worker=0x2aaaaf37f038)
at ../../CallManager/src/DP_CallControlTask.cpp:1043
4 Thread 0x2aaaae97e940 (LWP 28609) DP_Semaphore::dump (this=0x6e1460) at ../../Common/src/DP_Semaphore.cpp:21
2 Thread 0x2aaaad57c940 (LWP 28607) 0x00002aaaabe01ff3 in __find_specmb () from /lib64/libc.so.6
1 Thread 0x2aaaacb7b070 (LWP 28604) 0x00002aaaac1027c0 in __nptl_create_event () from /lib64/libpthread.so.0
(gdb)
【问题讨论】:
-
call this->availableWork->dump()怎么样? -
@timrau - 请参阅编辑。
-
为什么不将 ACE_Task 与 ACE_Message_Queue 一起使用,你可以很容易地创建一个线程池,其中包含一个消息队列供它们执行,请参阅 ACE 书籍了解更多详细信息