From: hf@colibri.de (Harald Fuchs)
Subject: Re: Looking for best design for using pthreads in C++ objects
Date: 1996/02/27 [thread overview]
Message-ID: <puag248wxl.fsf@themroc.colibri.de> (raw)
In-Reply-To: 312A0E5F.7B2C@ix.netcom.com
Webb Scales <scales@zko.dec.com> writes:
> David Brownell wrote:
>> One of the really nice techniques is to have a "Locker" class to grab mutexes
>> as needed, and then release it automatically on all exits. [...]
>> That kind of class really helps get rid of the bugs you have due
>> to locks not getting released uniformly on all codepaths.
> Hmmm...this approach makes me nervous. I assert that it's better to
> neglect to unlock a mutex than to unlock it when you shouldn't have.
Since the question was about pthreads in C++, you should use the
technique presented nevertheless. The problem is that you can leave
the critical section not only in the "normal" way (where unlock() gets
executed), but also by means of an exception thrown deep in your
calling chain. It's simply too easy to forget an appropriate catch clause.
next prev parent reply other threads:[~1996-02-27 5:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-02-19 5:00 Looking for best design for using pthreads in C++ objects Thom Anderson
1996-02-20 5:00 ` David Brownell
1996-02-26 5:00 ` Webb Scales
[not found] ` <313DEF19.5B69@ix.netcom.com>
[not found] ` <313EDB0B.FF6@zko.dec.com>
1996-03-08 5:00 ` David Brownell
1996-02-27 5:00 ` Harald Fuchs [this message]
1996-02-28 5:00 ` Webb Scales
1996-03-06 5:00 ` David Brownell
1996-02-20 5:00 ` Nasser Abbasi
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox