|
From: Sinan Y. <asm...@ya...> - 2004-11-06 11:54:34
|
Hi all,
I have a problem about valgrind scheduler. I'd like to
share it with you and discuss the solutions.
I am using pthreads library. I have created 2 threads
. One of them is the main program thread, the other
one is the thread which was created by the main
program thread.
At program exit, i try to kill the second thread on
main thread scope.
Main thread is executing this code :
...
...
delete 2ndThread;
...
...
Our 2nd Thread's destructor is coded like this :
2ndThread::~2ndThread()
{
quit = true;
sem_wait(wait_sem);
...
...
...
}
2nd Thread's thread loop is like this:
2ndThread::threadMethod()
{
while(!quit)
{
wait_timer_interrupt();
...
...
...
}
sem_post(wait_sem);
pthread_exit();
}
The 2nd thread is a thread that wakes with the timer
events. It wakes every 10 miliseconds. I have used
linux's setitimer for doing this. For setting 10 ms
timer interval ; i coded :
...
...
struct sigaction signal_action;
struct itimerval timer;
memset(&signal_action,0,sizeof(signal_action));
signal_action.sa_handler = (void
(*)(int))timer_handler;
sigaction(SIGALRM,&signal_action,NULL);
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = TIMER_INTERVAL * 1000 ;
timer.it_interval.tv_sec = 0 ;
timer.it_interval.tv_usec = TIMER_INTERVAL * 1000;
setitimer(ITIMER_REAL,&timer,NULL);
...
...
My timer handler function is :
void timer_handler(U32 signal_no)
{
sem_post(timer_semaphore);
}
And the "wait_timer_interrupt()" function called from
the threadMethod of the 2ndThread is :
void wait_timer_interrupt(void)
{
sem_wait(timer_semaphore);
}
My problem is:
When i use valgrind for tracing memory leaks, valgrind
exits my program execution ans gives a warning :
Thread 1: status = WaitCV, associated_mx = 0x34516160,
associated_cv = 0x34516178
==3861== at 0x34152EC1: pthread_cond_wait
(vg_libpthread.c:1454)
==3861== by 0x34156C6A: sem_wait
(vg_libpthread.c:2769)
==3861== by 0x804B512: bsem_wait (bthread.c:295)
==3861== by 0x80508DE: 2ndThread:.~2ndThread()
(timerthread.cpp:61)
==3861== by 0x804EF44: test_1()
(numerika_test.cpp:36)
==3861== by 0x804F4E3:
test_1__main__Test::TestFunction()
(numerika_test.cpp:94)
==3861== by 0x804BF93:
TestRegistery::runGroup(SimpleString const&)
(testregistery.cpp:138)
==3861== by 0x804C2F6: TestRegistery::runList()
(testregistery.cpp:230)
==3861== by 0x804BCD2: CppEntry (entry.cpp:9)
Thread 2: status = WaitCV, associated_mx = 0x345160E0,
associated_cv = 0x345160F8
==3861== at 0x34152EC1: pthread_cond_wait
(vg_libpthread.c:1454)
==3861== by 0x34156C6A: sem_wait
(vg_libpthread.c:2769)
==3861== by 0x804B512: bsem_wait (bthread.c:295)
==3861== by 0x8049F7F: wait_timer_interrupt
(btimer.c:38)
==3861== by 0x8050C70: 2ndThread::threadMethod()
(timerthread.cpp:183)
==3861== by 0x8050E99:
ThreadRoot::GeneralThreadEntry(void*)
(thread_root.cpp:25)
==3861== by 0x341519F0: thread_wrapper
(vg_libpthread.c:867)
==3861== by 0xB000EF61: do__quit
(vg_scheduler.c:1872)
Thread 3: status = WaitJoiner, associated_mx = 0x0,
associated_cv = 0x0
==3861== at 0x34151772: thread_exit_wrapper
(vg_libpthread.c:745)
==3861== by 0x34151A00: thread_wrapper
(vg_libpthread.c:873)
==3861== by 0xB000EF61: do__quit
(vg_scheduler.c:1872)
==3861==
==3861== Warning: pthread scheduler exited due to
deadlock
I couldn't find any deadlock state. Is it possible for
valgrind to stop interval timers before program exit ?
Because my 2ndThread is waiting on
"wait_timer_interrupt()" function and if linux's
interval timer is stopped by valgrind, there may be a
deadlock...
I couldn't find any solutions...
Waiting for your helps!
Thanks so much!
=====
__________________________________
Do you Yahoo!?
Check out the new Yahoo! Front Page.
www.yahoo.com
|
|
From: Tom H. <th...@cy...> - 2004-11-06 12:33:43
|
In message <200...@we...>
Sinan YILDIRIM <asm...@ya...> wrote:
> Main thread is executing this code :
> ...
> ...
> delete 2ndThread;
> ...
> ...
>
>
> Our 2nd Thread's destructor is coded like this :
>
> 2ndThread::~2ndThread()
> {
> quit = true;
> sem_wait(wait_sem);
> ...
> ...
> ...
> }
>
> 2nd Thread's thread loop is like this:
>
> 2ndThread::threadMethod()
> {
> while(!quit)
> {
> wait_timer_interrupt();
> ...
> ...
> ...
> }
>
> sem_post(wait_sem);
> pthread_exit();
> }
That code does not appear to be thread safe as you are writing to quit
in one thread and reading from it in another without any kind of locking.
> When i use valgrind for tracing memory leaks, valgrind
> exits my program execution ans gives a warning :
[ snipped ]
> ==3861==
> ==3861== Warning: pthread scheduler exited due to
> deadlock
>
> I couldn't find any deadlock state. Is it possible for
> valgrind to stop interval timers before program exit ?
> Because my 2ndThread is waiting on
> "wait_timer_interrupt()" function and if linux's
> interval timer is stopped by valgrind, there may be a
> deadlock...
It's a bug in valgrind - it doesn't consider signals when deciding
whether the process is deadlocked. The problem is that if you do
consider them then you pretty much have to remove the deadlock
detection altogether as you would only be able to consider the
process as deadlocked if all signals were blocked.
Actually I guess only signals with handlers can break a deadlock
so maybe it isn't that bad.
It's a bug anyway, and you're the second person to mention it
recently so could you please raise a bug for it.
Tom
--
Tom Hughes (th...@cy...)
Software Engineer, Cyberscience Corporation
http://www.cyberscience.com/
|