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-12 12:40:22 PST Xref: sparky comp.lang.c++:21089 comp.unix.osf.misc:108 Newsgroups: comp.lang.c++,comp.unix.osf.misc Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!darwin.sura.net!haven.umd.edu!decuac!pa.dec.com!engage.pko.dec.com!e2big.mko.dec.com!nntpd.lkg.dec.com!ktbush.ogo.dec.com!mjg From: mjg@ktbush.ogo.dec.com (Michael J. Grier) Subject: Re: Thread-safe libraries for C++? Message-ID: <1993Feb12.204022.25188@nntpd.lkg.dec.com> Sender: usenet@nntpd.lkg.dec.com (USENET News System) Reply-To: mjg@ktbush.ogo.dec.com (Michael J. Grier) Organization: Digital Equipment Corporation References: <1993Feb12.184345.19220@walter.bellcore.com> Date: Fri, 12 Feb 1993 20:40:22 GMT 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 |> ------------------------------------------------------------------------ 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