From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f678f,4753a27d8ceddc44 X-Google-Attributes: gidf678f,public X-Google-Thread: 109fba,4753a27d8ceddc44 X-Google-Attributes: gid109fba,public X-Google-ArrivalTime: 1993-02-13 20:11:28 PST Xref: sparky comp.lang.c++:20897 comp.unix.osf.misc:101 Newsgroups: comp.lang.c++,comp.unix.osf.misc Path: sparky!uunet!ukma!gatech!concert!decwrl!borland.com!pete From: pete@borland.com (Pete Becker) Subject: Re: Thread-safe libraries for C++? Message-ID: <1993Feb13.181757.1904@borland.com> Originator: pete@genghis.borland.com Sender: news@borland.com (News Admin) Organization: Borland International References: <1993Feb12.184345.19220@walter.bellcore.com> Date: Sat, 13 Feb 1993 18:17:57 GMT 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