From: gjb@fig.citib.com (Greg Brail)
Subject: Re: Thread-safe libraries for C++?
Date: Tue, 16 Feb 1993 22:30:36 GMT [thread overview]
Message-ID: <C2KBv1.DL@fig.citib.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?).
This means the standard library routines -- read, write, printf, malloc
and the like -- have been replaced with something that won't blow up when
used by multiple threads "at the same time." Most DCE implementations
do this by putting thread-safe versions of the appropriate functions
in a library that gets linked in before the standard C library so the thread-
safe versions get called first. Some just replace the C library with
a thread-safe one. IBM gives you a "thread-safe" copy of the C compiler.
Most also have a whole pile of macros that #define all the standard functions
to something else. So, "read" becomes "cma_read" or something like that.
This is fun when you try to make a class with a member called "read."
Personally, this is my least favorite DCE implementation decision. Fortunately,
one can turn it off and the thread-safe routines will still be used.
>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?
No to the first question and yes to the second. "new" and "delete" just
use malloc, which is thread-safe in most DCEs. iostream, however, probably
isn't. I don't know if anyone is working on thread-safe C++ standard
libraries. I doubt it, because such depends on the particular implementation
of threads.
However, Sun will soon (not too soon, but soon) have threads built
in to the OS, so presumably DCE will be able to use those and their
C++ compiler will work multithreadedly. HP is planning the same. For now,
however, C++ works fine with DCE if you're careful -- don't try to use
iostream for every thread, and stay away from weirdnesses like the tasking
library, for (I hope) obvious reasons.
>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.
Yes and no. Probably for the stream class, but not for all classes. The
USL Standard Components, for instance, aren't thread-safe. When I want
to put something on a hash table, I lock a mutex and put it there.
Same goes when I want to take something off. In this case, the thread
synchronization becomes part of the contract between the class and its
users.
It'd sure be nice if the class library handled locking for me (the
Booch Components provide for this), but it's not always the whole solution.
You may want the iostream library to prevent you from killing yourself
by having two threads write to cout at the same time, but you probably
don't want a whole bunch of threads writing to the screen at the same
time anyway. What if you want to print two lines, each using a different
"call" to cout? Even if cout does the locking for you, you still want
to put a lock around those two lines of code so the two lines of text
appear together on the screen.
greg
--
Greg Brail ------------------ Citibank -------------------- gjb@fig.citib.com
lose (lOOz) v. 1. a. To be unable to find; mislay. b. To incur the
deprivation of, as by negligence or accident. 2. To be unable to maintain,
sustain, or keep. 3. The most commonly misspelled word on Usenet.
prev parent reply other threads:[~1993-02-16 22:30 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
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 [this message]
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