bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

crash in detached thread in ThreadImpl::ThreadDestructor


From: Gernot Hillier
Subject: crash in detached thread in ThreadImpl::ThreadDestructor
Date: Mon, 6 Jan 2003 15:58:40 +0100
User-agent: KMail/1.4.3

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

Short: I use a detached thread which does "delete this" in its final()-method. 
It crashes when calling terminate() from another thread.

Long: 

I have a base class BaseClass implementing a CommonC++-Thread. It has a 
final()-method which does "delete this" and a run() method which will do some 
work. BaseClass::~BaseClass() calls terminate() like told in the docs.

I have a derived "class DerivedClass: public BaseClass". It reimplements 
run(). This run() will call BaseClass::run() somewhere in the middle.

An object is created from DerivedClass which is started with detach(). This 
object is later on called to terminate(). 

This will cause a crash:

0x400adb70 in ost::ThreadImpl::ThreadDestructor(ost::Thread*) (th=0x8157720) 
at thread.cpp:878
878             if (th->priv->_type == threadTypeDummy)
(gdb) bt
#0  0x400adb70 in ost::ThreadImpl::ThreadDestructor(ost::Thread*) 
(th=0x8157720) at thread.cpp:878
#1  0x400accfa in ccxx_thread_destructor (arg=0x8157720) at thread.cpp:884
#2  0x4003cb16 in __pthread_destroy_specifics () from /lib/libpthread.so.0
#3  0x40038734 in __pthread_do_exit () from /lib/libpthread.so.0
#4  0x4003ba61 in pthread_handle_sigcancel () from /lib/libpthread.so.0
#5  <signal handler called>
#6  0x40304d01 in nanosleep () from /lib/libc.so.6
#7  0x4003e58c in nanosleep () from /lib/libpthread.so.0
#8  0x400afb66 in ost::Thread::sleep(unsigned long) (timeout=100) at 
friends.cpp:134
#9  0x08067a56 in DerivedClass::run() (this=0x8157720) at idlescript.cpp:39
#10 0x400adb06 in ost::ThreadImpl::ThreadExecHandler(ost::Thread*) 
(th=0x8157720) at thread.cpp:865
#11 0x400acd20 in ccxx_exec_handler (th=0x8157720) at thread.cpp:889
#12 0x400391b0 in pthread_start_thread () from /lib/libpthread.so.0
#13 0x4003922f in pthread_start_thread_event () from /lib/libpthread.so.0

Log output shows me that the thread object gets deleted *before* this crash. 
The thread seems to be still in run() (see #9) but its object is already 
deleted. So the cause for the crash is clear. 

I don't understand how this can happen - especially why final() could be 
called but run() is still active?!

cancelMode is set to cancelDeferred.

Can someone perhaps give me some idea where to look for this bug? I'm not very 
well experienced with libpthread unfortunately, so I only know what is told 
to me in the Docs of CommonC++.

I can work around this by using some flag which is checked in run(). If I just  
set this flag from outside and don't use terminate(), everything is fine. 

Perhaps some of you have some idea??

TIA!

- -- 
Ciao,

Gernot
"Der Horizont vieler Menschen ist ein Kreis mit Radius Null - und das nennen 
sie ihren Standpunkt." (A. Einstein)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+GZmik997/GGeSeIRAqrOAKCol8vbUYolIq7RJ4DMwvStefD7sgCfaB9I
rLjEU/OO+oQClxlNozv7REg=
=6kxu
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]