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-17 10:15:53 PST Xref: sparky comp.lang.c++:21218 comp.unix.osf.misc:115 Newsgroups: comp.lang.c++,comp.unix.osf.misc Path: sparky!uunet!gatech!destroyer!fmsrl7!lynx.unm.edu!umn.edu!csus.edu!netcom.com!nagle From: nagle@netcom.com (John Nagle) Subject: Re: Thread-safe libraries for C++? Message-ID: <1993Feb17.181553.499@netcom.com> Organization: Netcom - Online Communication Services (408 241-9760 guest) References: <1993Feb12.184345.19220@walter.bellcore.com> Date: Wed, 17 Feb 1993 18:15:53 GMT 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