Pthreads: how to insure mutex is unlocked when a thread dies.
- From: "Alan McKenney" <alan_mckenney1@xxxxxxxxx>
- Date: 28 Jul 2006 12:46:44 -0700
(I looked in the SUN pthreads book, the Solaris 10 man pages, and in
the c.p.t FAQ,
and didn't find anything about this.)
I'm writing an application that will spin off a thread to handle
incoming messages
from another system. In the past, we've had problems with such threads
dying,
e.g., due to a SEGV or something, and the rest of the program merrily
going
on, not noticing that the thread is gone.
Anyway, I was planning to have this thread lock a mutex when it starts,
and
unlock it when it's done, e.g., when the application notifies it to
quit. The
application will set the notification variable, and then wait on the
mutex.
I'm concerned that if the thread dies before the application notifies
it to quit, the
lock will never get unlocked.
I'm using C++, and have an RAII class that will release the lock in
case of
an exception or other return, but I haven't been able to find out
whether this
will also handle things like SEGV.
1. Will this handle abnormal termination, such as SEGV in the thread?
2. If not, is there a good way to make sure the mutex is unlocked,
regardless
of how the thread dies?
Our applications are sort of like server applications -- they run
without much
active supervision, and they have to raise a alarm (or crash) in order
to get
Operations to look at them -- so they have to behave in some sensible
fashion
even when they have errors.
-- Alan McKenney
.
- Follow-Ups:
- Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- From: David Hopwood
- Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- From: Steve Watt
- Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- From: Chris Friesen
- Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- From: Sean Kelly
- Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- Prev by Date: Re: Recursive mutex that can be waited upon (pthread)
- Next by Date: Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- Previous by thread: how does sleep waiting on an event and triggering that event work in linux
- Next by thread: Re: Pthreads: how to insure mutex is unlocked when a thread dies.
- Index(es):
Relevant Pages
|