🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.programming.threads
Article #6

Re: Looking for best design for using pthreads in C++ objects

#6
From: Harald Fuchs
Date: Tue, 27 Feb 1996 18:07
16 lines
1818 bytes
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.
Technical Details
Message-ID: <puag248wxl.fsf@themroc.colibri.de>
Path: arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mail
References: <3128ff8b.666031216@news.clark.net> <312A0E5F.7B2C@ix.netcom.com> <31320705.41C6@zko.dec.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!rz.uni-karlsruhe.de!not-for-mail
From: hf@colibri.de (Harald Fuchs)
Newsgroups: comp.programming.threads,comp.lang.c++,comp.unix.osf.osf1,comp.unix.programmer,comp.object
Subject: Re: Looking for best design for using pthreads in C++ objects
Date: 27 Feb 1996 19:07:02 +0100
Organization: Colibri GmbH, Germany
Sender: hf@themroc.colibri.de
Message-ID: <puag248wxl.fsf@themroc.colibri.de>
References: <3128ff8b.666031216@news.clark.net> <312A0E5F.7B2C@ix.netcom.com>
 <31320705.41C6@zko.dec.com>
NNTP-Posting-Host: teco10a.teco.uni-karlsruhe.de
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
In-reply-to: Webb Scales's message of Mon, 26 Feb 1996 14:16:21 -0500
X-WWW-Home-Page: http://www.colibri.de/~hf/
X-PGP-Public-Key: finger hf@colibri.de
X-PGP-Fingerprint: 09 4E C4 A2 B2 C5 33 1A  79 80 5D 39 BD 9B 89 39
X-Disclaimer: Kore wa Colibri no iken dewa arimasen
X-Newsreader: Gnus v5.0.9