Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
From: amewaldu@cayley.uwaterloo.ca (Andrew Walduck)
Subject: Re: Thread-safe libraries for C++?
Date: Sun, 14 Feb 1993 22:26:04 GMT	[thread overview]
Message-ID: <C2GMBH.Ap8@undergrad.math.waterloo.edu> (raw)
In-Reply-To: 1993Feb13.181757.1904@borland.com

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




  reply	other threads:[~1993-02-14 22:26 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 [this message]
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
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