Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: denham@denham.zk3.dec.com (Jeffrey M. Denham)
Subject: Re: Threads
Date: 1995/04/11	[thread overview]
Message-ID: <1995Apr11.170345.14566@decvax.dec.com> (raw)
In-Reply-To: 3lpjq8$r07@bcarh8ab.bnr.ca


In article <3lpjq8$r07@bcarh8ab.bnr.ca>, danr@bnr.ca (Dan Reynolds) writes:
|>Since we are blessed by so many DEC employees in our newsgroup, I have a 
|>question regarding DEC threads and the use of thread safe code.
|>
|>To obtain thread safe code one must remove or protect references to the 
|>following dependencies:
|>
|>	o Static (or global) read-write data
|>        o File descriptors shared between threads
|>	o REFERENCES TO GLOBAL ERRNO
|>	o calls to other nonthread-safe routines.
|>
|>
|>The problem is that the GLOBAL ERRNO is used by many UNIX functions, such as
|>file I/O, sockets, semaphores, etc..., and even the PTHREAD library. 
|>
|>So, my question is, how can one write thread safe code, when a significant 
|>number of UNIX functions are using the GLOBAL ERRNO, which includes the PTHREAD
|>library? 
|>
|>thanks...
|>
|>Dan
|>
|>-- 
|>Dan Reynolds            | (613)-763-7584 | Opinions expressed are my own and do
|>Bell-Northern Research  |                | not necessarily reflect my employer.
|>Ottawa, Ontario, Canada |   danr@bnr.ca  | 
|>-------------------------------------------------------------------------------
|>

Here's a reply from a DECthreads developer who hasn't had time to monitor the
newsgroup lately:

That's simply untrue! DECthreads and libc_r do write the global "int errno" 
when they report an error, but that's strictly secondary and only for 
compatibility with code that's not built using _REENTRANT. They ALSO set a 
per-thread errno, and that's what all code should be reading when using
thread-safe libraries.

DECthreads provides _errno(), which returns the address of a per-thread errno
cell. And (when the _REENTRANT or _THREADSAFE flag is defined) errno.h #defines
errno to call _errno() and dereference it. The result is "virtually 
indistinguishable" from a global errno, but it's completely thread safe with
no synchronization.

Including cma.h or pthread.h automatically defines _REENTRANT, so as long as 
errno.h is included after one of those you get it for free. If you don't
include one of those headers, or if you include errno.h first, you'll get the
global errno. 



  parent reply	other threads:[~1995-04-11  4:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-04-03  4:00 Threads Dan Reynolds
1995-04-06  4:00 ` Threads Spider Boardman
1995-04-11  4:00 ` Jeffrey M. Denham [this message]
1995-04-19  4:00   ` Threads Shaheen Ali
  -- strict thread matches above, loose matches on Subject: below --
1994-11-28 16:19 threads ron harter
1994-11-29 21:56 ` threads Jay R. Talbott
1994-08-03 21:05 threads Lawrence A.  Palmer
1994-08-03 23:22 ` threads Matt Thomas
1994-08-04  1:05   ` threads Sinan Karasu
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