Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
From: mjg@ktbush.ogo.dec.com (Michael J. Grier)
Subject: Re: Thread-safe libraries for C++?
Date: Fri, 12 Feb 1993 20:40:22 GMT	[thread overview]
Message-ID: <1993Feb12.204022.25188@nntpd.lkg.dec.com> (raw)
In-Reply-To: 1993Feb12.184345.19220@walter.bellcore.com


In article <1993Feb12.184345.19220@walter.bellcore.com>, doel@bbq.uucp (Mike Doel) writes:
|>
|>Our group is doing a little research into which implementation of RPC's we
|>wish to use for an upcomming project.  We're leaning towards the DCE
|>standard but for one small thing.  As I understand it, the RPC mechanism for
|>DCE is implemented using DCE threads.  In order to use threads, you must use
|>"thread safe" libraries.  Apparently, the standard C libraries aren't thread
|>safe.  To counteract this, "jacket" routines have been developed which make
|>the standard Unix libraries thread safe (what does that mean?).

   (I'm not directly involved with DCE, but I've been using pthreads and
DEC's CMA thread programming interface for a few years, so I might be able
to help...)

   It means that there is liberal use of #define to change your invocation
of standard library functions to instead call the DCE jacket, which is
a function which will perform the work behind your back to ensure that the
operation is carried out in a thread-safe manner.  This usually means locking
some global "calling out to non-thread-safe library" mutex, performing
the operation, and then unlocking the mutex.  (CMA provides two calls for
this, cma_lock_global() and cma_unlock_global().  I'm not crazy about writing
code using pthreads while it's still undergoing incompatible changes draft-
to-draft.)

   For some operations, the jackets go farther to give you some semblance of
thread-synchronous operation, for example select().  Your mileage will
vary depending on your UNIX variant and how serious its kernel is about not
blocking when non-blocking I/O is requested.

|>
|>My question is, has anything been done to make C++ libraries safe?  If not,
|>can we still develop C++ applications in a DCE threaded environment?  I
|>talked to someone at Transarc (who has a DCE implementation for SunOS 4.1.2)
|>and he suggested we do something like this:
|>
|>	//obtain the "mutex", however that's done
|>
|>	cout << "Now it's safe to do output"
|>
|>	//release the mutex
|>
|>This strikes me as terribly kludgy.  Obtaining and release the mutex should
|>be done by the stream class, not the user of it.

   Kludgy, disgusting, but the only safe way to be portable.  If you are
sure that every platform you're interested in has a thread-safe stream class,
there is hope, but often you have to tap on whoever is providing the
stream implementation and convince them that it's worth the "overhead" for
the thread-safe operation.

   Usually you'll find that you have to only synchronize on a per-object
basis.  I.e. if you have 20 threads accessing 20 different streams, as
long as there aren't any static variables or static members in the
classes involved, you'll probably be OK.  Again, contact whoever wrote the
classes for definitive information, there is a suprising amount of non-
reentrant code out there.

|>-- 
|>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|>Mike Doel				<doel@bae.bellcore.com>
|>
------------------------------------------------------------------------
I'm saying this, not Digital.  Don't hold them responsibile for it!

Michael J. Grier                           Digital Equipment Corporation
(508) 496-8417                             mjg@ktbush.dec.com
Stow, Mass, USA                            Mailstop OGO1-1/E16


  parent reply	other threads:[~1993-02-12 20:40 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-12 18:43 Thread-safe libraries for C++? Mike Doel
1993-02-12 12:22 ` Jon C. R. Bennett
1993-02-13 18:17   ` Pete Becker
1993-02-14 22:26     ` Andrew Walduck
1993-02-12 20:40 ` Michael J. Grier [this message]
1993-02-16 17:54   ` Jim Robinson
1993-02-16 23:14     ` Michael J. Grier
1993-02-18  2:51     ` Michael Joosten
1993-02-18 22:05     ` Greg Brail
1993-02-16 22:29 ` Bob Martin
1993-02-17 18:15   ` John Nagle
1993-02-18 14:37     ` Andrew Condon
1993-02-22 20:22       ` Greg Brail
1993-02-16 22:30 ` Greg Brail
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