0

I am trying to implement a thread pool using ACE Semaphore library. It does not provide any API like sem_getvalue which is in Posix semaphore. I need to debug some flow which is not behaving as expected. Can I examine the semaphore in GDB. I am using Centos as OS.

I initialized two semaphores using the default constructor providing count 0 and 10. I have declared them as static in the class and initialized it in the cpp file as

DP_Semaphore ThreadPool::availableThreads(10);
DP_Semaphore ThreadPool::availableWork(0);

But when I am printing the semaphore in GDB using the print command, I am getting the similar output

(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
  }
}

Is there a tool which can help me here, or shall I switch to Posix thread and re-write all my code.

EDIT: As requested by @timrau the output of call 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)
Abhishek
  • 2,543
  • 4
  • 34
  • 46
  • How about `call this->availableWork->dump()` ? – timrau Mar 10 '14 at 09:58
  • Why not use the ACE_Task with the ACE_Message_Queue, than you can pretty easily create a thread pool with a queue of messages with work for them to execute, see the ACE books for more details – Johnny Willemsen Mar 10 '14 at 10:30

1 Answers1

0

sema.semaphore_.sema_ in your code looks like a pointer. Try to find it's type in the ACE headers, then convert it to a type and print:

(gdb) p *((sem_t)0x6fe570)

Update: try to convert the address within the structure you posted to sem_t. If you use linux, ACE should be using posix semaphores, so type sem_t must be visible to gdb.

Pavel Davydov
  • 3,379
  • 3
  • 28
  • 41
  • It has a structure ACE_sema_t which has sem_t sema_. But gdb gives No symbol "ACE_sema_t" in current context error when I try to print it.http://www.dre.vanderbilt.edu/Doxygen/5.7.3/html/ace/a00572.html#a01104c19fd0d768065b23717427c6a94 – Abhishek Mar 10 '14 at 10:37