From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,4753a27d8ceddc44 X-Google-Attributes: gid109fba,public X-Google-Thread: f678f,4753a27d8ceddc44 X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1993-02-15 06:52:04 PST Xref: sparky comp.lang.c++:21000 comp.unix.osf.misc:105 Newsgroups: comp.lang.c++,comp.unix.osf.misc Path: sparky!uunet!pipex!doc.ic.ac.uk!agate!usenet.ins.cwru.edu!howland.reston.ans.net!usc!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watmath!undergrad.math.waterloo.edu!cayley.uwaterloo.ca!amewaldu From: amewaldu@cayley.uwaterloo.ca (Andrew Walduck) Subject: Re: Thread-safe libraries for C++? Message-ID: Sender: news@undergrad.math.waterloo.edu Organization: University of Waterloo References: <1993Feb12.184345.19220@walter.bellcore.com> <1993Feb13.181757.1904@borland.com> Date: Sun, 14 Feb 1993 22:26:04 GMT 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 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