* Re: Thread-safe libraries for C++?
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-12 20:40 ` Michael J. Grier
` (2 subsequent siblings)
3 siblings, 1 reply; 14+ messages in thread
From: Jon C. R. Bennett @ 1993-02-12 12:22 UTC (permalink / raw)
doel@bbq.uucp (Mike Doel) writes:
> //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.
the stream class should not obtain the mutex for you since few aplications
would need it, if thats what you want then, write a subclass of streams
that does the locks and then just calls the normal stream methods
jon
^ permalink raw reply [flat|nested] 14+ messages in thread
* Thread-safe libraries for C++?
@ 1993-02-12 18:43 Mike Doel
1993-02-12 12:22 ` Jon C. R. Bennett
` (3 more replies)
0 siblings, 4 replies; 14+ messages in thread
From: Mike Doel @ 1993-02-12 18:43 UTC (permalink / raw)
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?).
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.
Does anyone have any experience they can offer?
Thanks
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mike Doel <doel@bae.bellcore.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-12 18:43 Thread-safe libraries for C++? Mike Doel
1993-02-12 12:22 ` Jon C. R. Bennett
@ 1993-02-12 20:40 ` Michael J. Grier
1993-02-16 17:54 ` Jim Robinson
1993-02-16 22:29 ` Bob Martin
1993-02-16 22:30 ` Greg Brail
3 siblings, 1 reply; 14+ messages in thread
From: Michael J. Grier @ 1993-02-12 20:40 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-12 12:22 ` Jon C. R. Bennett
@ 1993-02-13 18:17 ` Pete Becker
1993-02-14 22:26 ` Andrew Walduck
0 siblings, 1 reply; 14+ messages in thread
From: Pete Becker @ 1993-02-13 18:17 UTC (permalink / raw)
In article <gfT2ATS00WBEA4Tjhf@andrew.cmu.edu> jb7m+@andrew.cmu.edu (Jon C. R. Bennett) writes:
>
>the stream class should not obtain the mutex for you since few aplications
>would need it, if thats what you want then, write a subclass of streams
>that does the locks and then just calls the normal stream methods
>
That doesn't really solve the problem:
cout << "This is " << "a test\n";
Even if the inserters handle serialization themselves, there's no
guarantee that you won't get a context switch between invocations of the
inerters. If two threads both called this code, the result could be
something like this:
This is This is a test
a test
There are really two separate issues that a programmer faces when
dealing with multiple threads: making sure that individual functions can be
used safely with threads, and making sure that the program logic is correct
when using threads. Serialization control inside the iostream library
addresses the first issue, but not the second. Without serialization control,
this erroneous program may well crash. With it, the program displays
nonsense. From a user's perspective, there's not a big difference between the
two results.
-- Pete
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-13 18:17 ` Pete Becker
@ 1993-02-14 22:26 ` Andrew Walduck
0 siblings, 0 replies; 14+ messages in thread
From: Andrew Walduck @ 1993-02-14 22:26 UTC (permalink / raw)
The "thread aware" version of streams that I've seen implements locking of
the stream as a manipulator.
Ie:
cout << "This is " << "a test\n";
Would be written as:
cout << lock << "This is" << "a test\n" << unlock;
Andrew
In article <1993Feb13.181757.1904@borland.com> pete@borland.com (Pete Becker) writes:
>In article <gfT2ATS00WBEA4Tjhf@andrew.cmu.edu> jb7m+@andrew.cmu.edu (Jon C. R. Bennett) writes:
>>
>>the stream class should not obtain the mutex for you since few aplications
>>would need it, if thats what you want then, write a subclass of streams
>>that does the locks and then just calls the normal stream methods
>>
>
> That doesn't really solve the problem:
>
> cout << "This is " << "a test\n";
>
> Even if the inserters handle serialization themselves, there's no
>guarantee that you won't get a context switch between invocations of the
>inerters. If two threads both called this code, the result could be
>something like this:
>
> This is This is a test
> a test
>
> There are really two separate issues that a programmer faces when
>dealing with multiple threads: making sure that individual functions can be
>used safely with threads, and making sure that the program logic is correct
>when using threads. Serialization control inside the iostream library
>addresses the first issue, but not the second. Without serialization control,
>this erroneous program may well crash. With it, the program displays
>nonsense. From a user's perspective, there's not a big difference between the
>two results.
> -- Pete
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-12 20:40 ` Michael J. Grier
@ 1993-02-16 17:54 ` Jim Robinson
1993-02-16 23:14 ` Michael J. Grier
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Jim Robinson @ 1993-02-16 17:54 UTC (permalink / raw)
Michael J. Grier (mjg@ktbush.ogo.dec.com) wrote:
>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.
[and]
> 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.
Is it correct to say then that if one forgets to #include the relevant
header the result is that the native select() is used which could block
the entire process instead of just the calling thread? Is so, isn't this
an incredibly easy mistake to make which may not be terribly easy to
catch?
And, are the jacket routines also used to map blocking I/O calls (e.g.
read(), recvfrom()) to non-blocking versions?
[Followup to comp.unix.osf.misc only]
--
Jim Robinson
robinson@mdd.comm.mot.com
{ubc-cs!van-bc,uunet}!mdivax1!robinson
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-12 18:43 Thread-safe libraries for C++? Mike Doel
1993-02-12 12:22 ` Jon C. R. Bennett
1993-02-12 20:40 ` Michael J. Grier
@ 1993-02-16 22:29 ` Bob Martin
1993-02-17 18:15 ` John Nagle
1993-02-16 22:30 ` Greg Brail
3 siblings, 1 reply; 14+ messages in thread
From: Bob Martin @ 1993-02-16 22:29 UTC (permalink / raw)
doel@bbq.uucp (Mike Doel) writes:
|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?).
First, the definition of "thread safe". In an operating system that
supports multiprocessing, a thread is most often a process. It is an
execution context managed by the operating system. The operating
system can suspend the execution of one thread and start or continue
the execution of another at any arbitrary time. Thus, if your code is
running in one thread, it may get arbitrarily interrupted while the
code from someone elses program runs.
This has severe implications for the management of any resources that
the two threads share in common. For example, if both threads
attempted to output messages to cout, the characters within the
messages could be interleaved as the operating system alternately
suspended and continued the two threads.
A thread safe library is one in which the operations are guaranteed to
remain sane and safe in the presence of multiple threads of execution.
|My question is, has anything been done to make C++ libraries safe?
Some C++ class libraries are thread safe. The Booch Components are
one example. I am not directly familiar with any thread-safe versions
of the standard C or C++ libraries.
|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
A mutex is a semaphore. It is a flag which says "I have it, you cant
use it!". You sieze the mutex before you mess with a shared resource.
You release it when you are done. If you can't sieze the mutex, then
someone else must have it, so you wait until they release it. Most
operating systems provide mutex tools in one form or another.
I assume that your correspondent was not talking about any particular
mutex, but one that you created for yourself, and that all your
threads used.
|This strikes me as terribly kludgy. Obtaining and release the mutex should
|be done by the stream class, not the user of it.
That would be nice. Perhaps you should derive a mutex using subclass
of ios....
--
Robert Martin | Design Consulting | Training courses offered:
R. C. M. Consulting | rmartin@rational.com | Object Oriented Analysis
2080 Cranbrook Rd. | Tel: (708) 918-1004 | Object Oriented Design
Green Oaks, Il 60048| Fax: (708) 918-1023 | C++
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-12 18:43 Thread-safe libraries for C++? Mike Doel
` (2 preceding siblings ...)
1993-02-16 22:29 ` Bob Martin
@ 1993-02-16 22:30 ` Greg Brail
3 siblings, 0 replies; 14+ messages in thread
From: Greg Brail @ 1993-02-16 22:30 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
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
2 siblings, 0 replies; 14+ messages in thread
From: Michael J. Grier @ 1993-02-16 23:14 UTC (permalink / raw)
In article <1993Feb16.175330.11699@mdivax1.uucp>, robinson@mdivax1.uucp (Jim Robinson) writes:
|>Michael J. Grier (mjg@ktbush.ogo.dec.com) wrote:
|>> 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.
|>
|>[and]
|>
|>> 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.
|>
|>Is it correct to say then that if one forgets to #include the relevant
|>header the result is that the native select() is used which could block
|>the entire process instead of just the calling thread? Is so, isn't this
|>an incredibly easy mistake to make which may not be terribly easy to
|>catch?
You can work around it in a given project by having one of your central
h files #include the relevant definitions. That's how we handle it, and
it usually works out OK.
Depending on your environment, it may be very easy to catch -- you'll
hang! ;-) In a situation where a blocking I/O doesn't block for long,
you'll just get degraded performance.
Since followups were redirected to comp.unix.osf.misc, I assume we're
talking in the context of OSF/1, so with kernel support for threads, things
may be different. There are different models of how pthreads threads map
onto OSF/1 kernel threads, so it depends upon the mapping chosen. If threads
always map one-to-one to kernel threads, I believe that you will not have a
problem. If the mapping is not one-to-one, you can/will get one of the kernel
threads hung in a select() or other blocking I/O call.
|>
|>And, are the jacket routines also used to map blocking I/O calls (e.g.
|>read(), recvfrom()) to non-blocking versions?
|>
Yes. It's true of any call which blocks the running thread while in
the kernel.
|>[Followup to comp.unix.osf.misc only]
|>--
|>Jim Robinson
|>robinson@mdd.comm.mot.com
|>{ubc-cs!van-bc,uunet}!mdivax1!robinson
|>
|>
------------------------------------------------------------------------
I'm saying this, not Digital. Don't hold them responsibile for it!
Michael J. Grier Digital Equipment Corporation
(508) 496-8417 mjg@ktbush.ogo.dec.com
Stow, Mass, USA Mailstop OGO1-1/E16
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-16 22:29 ` Bob Martin
@ 1993-02-17 18:15 ` John Nagle
1993-02-18 14:37 ` Andrew Condon
0 siblings, 1 reply; 14+ messages in thread
From: John Nagle @ 1993-02-17 18:15 UTC (permalink / raw)
rmartin@thor.Rational.COM (Bob Martin) writes:
>doel@bbq.uucp (Mike Doel) writes:
>|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?).
Much of the problem comes from a lack of any C++ language support
for concurrency. All locking must be coded with executable statements,
not implied in declarations. C++ has nothing like Modula or Ada monitors.
It would be desirable to be able to associate a mutex with either
a class or a class instance, as appropriate, so that the lock would be
set upon entry to the class via a public class member function
and released on return from that function. This would be the OOP
equivalent of a monitor. (Private functions don't need locking under
this model, since they are called from within the class.)
If a class has no static variables, then locking should, by default,
be at the instance level, so that multiple instances of the class can
be used simultaneously. If a class does have static variables, then
by default they should be protected by a class-level lock.
Sometimes you want different locking semantics, when you are
explicitly coding interprocess communication (as when implementing a
queue), and it should thus be possible to override the default.
A problem with class reentrancy remains, where a class member
calls out of the class and eventually, back in via a public member
function. This will deadlock. Of course, if the class isn't designed
for this sort of thing, it will probably do the wrong thing anyway.
A typical situation is when a function called by an iterator modifies
the list being iterated over. Existing systems screw up; with this kind
of locking, they would deadlock.
Ideally, you'd like to have a smart linker which could delete all
unnecessary locks after tracing the call graph, as well as detecting
the obvious deadlocks, but that's in the future.
Is anyone designing something like this?
John Nagle
John Nagle
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
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
2 siblings, 0 replies; 14+ messages in thread
From: Michael Joosten @ 1993-02-18 2:51 UTC (permalink / raw)
In article <1993Feb16.175330.11699@mdivax1.uucp> robinson@mdivax1.uucp (Jim Robinson) writes:
Is it correct to say then that if one forgets to #include the relevant
header the result is that the native select() is used which could block
the entire process instead of just the calling thread? Is so, isn't this
an incredibly easy mistake to make which may not be terribly easy to
catch?
Sure ! And in the context of C++, the 'mechanism' used in CMA threads is even
more difficult: Guess what happens if you have some member functions like
'XXX.open(...)' and so on.... If you don't plan the introduction of threads
(here, OSF/DEC's CMA threads) rather early you are likely to face some
renamings since the mentioned header file just contains of
#define write cma_read
#define fopen cma_fopen
and so on...
And, are the jacket routines also used to map blocking I/O calls (e.g.
read(), recvfrom()) to non-blocking versions?
Yes.
Michael
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Michael Joosten | Tel. : (+49) (+) 5251-284 120 |
| CADLAB | Fax : (+49) (+) 5251-284 140 |
| Bahnhofstr. 32 | E-Mail: joost@cadlab.de |
| D-4790 Paderborn | ...!uunet!unido!cadlab!joost |
| FRG | Mass mail to: joost@pbinfo.uni-paderborn.de |
|--------------------------------------------------------------------------|
| CADLAB is a cooperation between Uni-GH Paderborn & SNI AG |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-17 18:15 ` John Nagle
@ 1993-02-18 14:37 ` Andrew Condon
1993-02-22 20:22 ` Greg Brail
0 siblings, 1 reply; 14+ messages in thread
From: Andrew Condon @ 1993-02-18 14:37 UTC (permalink / raw)
My $0.02:
Everyone following-up so far has used cout as an example of a thread unsafety
so I just thought I would mention (from direct experience) that I think the
thorniest problem with non-thread safe libs concerns memory management, ie
new and delete.
--
Andrew
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
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
2 siblings, 0 replies; 14+ messages in thread
From: Greg Brail @ 1993-02-18 22:05 UTC (permalink / raw)
In article <1993Feb16.175330.11699@mdivax1.uucp> robinson@mdd.comm.mot.com (Jim Robinson) writes:
>Michael J. Grier (mjg@ktbush.ogo.dec.com) wrote:
>> (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.
>
>Is it correct to say then that if one forgets to #include the relevant
>header the result is that the native select() is used which could block
>the entire process instead of just the calling thread? Is so, isn't this
>an incredibly easy mistake to make which may not be terribly easy to
>catch?
Most DCE implementations I've seen actually put thread-safe versions of
system calls and standard library functions in a library that gets linked
in with DCE. Thus, you get the "proper" versions of these functions
even if you deliberately turn off the #defines (which is sometimes
necessary).
Yes, all this #defining and re-defining is a mess, and I hope it gets easier
when more vendors offer user-accessible threads in the OS. Right now,
all this is one reason why the toughest thing about DCE programming is
writing the makefile.
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.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Thread-safe libraries for C++?
1993-02-18 14:37 ` Andrew Condon
@ 1993-02-22 20:22 ` Greg Brail
0 siblings, 0 replies; 14+ messages in thread
From: Greg Brail @ 1993-02-22 20:22 UTC (permalink / raw)
In article <1993Feb18.143708.19048@maths.tcd.ie> afcondon@maths.tcd.ie (Andrew Condon) writes:
>My $0.02:
>Everyone following-up so far has used cout as an example of a thread unsafety
>so I just thought I would mention (from direct experience) that I think the
>thorniest problem with non-thread safe libs concerns memory management, ie
>new and delete.
"new" and "delete" work fine if malloc and free are implemented in a
thread-safe manner. The DCE implementations I've used provide thread-
safe versions of malloc and free in the libraries. Therefore, C++ code
has no trouble calling new and delete in a multithreaded program.
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.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~1993-02-22 20:22 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox