Defect Report concerning: IEEE Std. 1003.1c-1995, ISO/IEC 9945-1:1990 AMD 2 - Threads
Clause: 2.3.9
PASC Interpretation Ref: pasc-1003.1c-39
Topic: thread - safety


This is an unapproved interpretation of PASC 1003.1c-1995, ISO/IEC 9945-1:1990 AMD 2 - Threads.

Use of the information contained in this unapproved document is at your own risk.

Last update: 30 March,1998


								1003.1c-95  #39

 _____________________________________________________________________________

	Interpretation Number:	XXXX
	Topic:               thread - safety
	Relevant Sections:   2.3.9

Interpretation Request: (Defect Report)
-----------------------

	From: Andrew Josey (on behalf of the X/Open Base working group)

Part 1. Interpretation Request for:
   IEEE Std 1003.1c-1995 as contained in:
   ISO/IEC 9945-1:1996(E), ANSI/IEEE Std. 1003.1, 1996 Edition.
   Subsection 2.3.9, Page 32, Line 754-761.

Question:
The referenced paragraph says that all POSIX.1 and ISO C functions except
those enumerated within the paragraph shall be thread safe. Why are the
functions getenv(), localeconv(), and strerror() not in the list of exceptions?
Their absence implies that they SHALL be thread safe, yet their definitions
each state that the object pointed to by their return value MAY be overwritten
by a subsequent call to the same function. If this is the case, implementations
cannot provide thread safety through internal synchronization because the return
object as seen by one thread may be corrupted by another thread AFTER the
function returns to the first thread, but before the first thread is finished
utilizing or copying the object. Although it is quite possible for an
implementation to provide these in a thread safe fashion using thread specific
data with destructors, the function definitions allow non-thread safe behavior,
directly contradicting this paragraph. These 3 functions fall into the same
general category as asctime() or ttyname(), and should be in this list.  In the
future, thread safe versions of these functions should be included in the
standard (getenv_r, localeconv_r, strerror_r).

Suggested Correction:
Add getenv(), localeconv(), and strerror() to the list of functions that need
not be thread safe.


Interpretation response
------------------------
The standard is clear that getenv(), localeconv(), and strerror() must
be thread-safe. A conforming implementations shall satisfy this
condition.

However, concerns have been raised in the interpretation committee that
this was not the intent of the working and balloting groups.  This is
being referred to the sponsor consideration.     


Rationale
-------------
It appears that the standard has a defect - the working group and the
balloting group seems to have missed these three functions. Note, that
the standard states that all POSIX.1 and ISO C be functions be thread
safe but for a list of exceptions that have _r equivalents. These
functions should have been part of the list of exceptions.

A getenv_r() function should clearly be added.  Likewise requirements
for localeconv_r() and strerror_r() should added for systems that
provide localeconv() and strerror().  (Note that these ANSI C
functions are not required by IEEE Std 1003.1.) 

Forwarded to Interpretations group: Dec 9 1996
Proposed resolution: Jan 17 1997
Finalised: Feb 14 1997