Defect Report concerning: IEEE Std. 1003.1c-1995, ISO/IEC 9945-1:1990 AMD 2 - Threads
Clause: POSIX.1-1996, Page 340, clause 16.2.5.2, ll 249
PASC Interpretation Ref: pasc-1003.1c-49
Topic: pthread_exit and exit status


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  #49

 _____________________________________________________________________________

	Interpretation Number:	XXXX
        Topic:                  pthread_exit and exit status
        Relevant Sections:      POSIX.1-1996, Page 340, clause 16.2.5.2, ll 249

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

	Date: Sun, 1 Feb 1998 02:55:22 -0600
	From:  Andrew Josey (ajosey@rdg.opengroup.org)


WG15 Status Block (official use only):
------------------------------------------------------------------------
 1  Defect report number: IS9945-1:1996 #1c-49

 2  Submitter:  IEEE PASC
		March 12 1998

 3  Addressed to: JTC1/SC22  /WG15
                 editor's group on IS 9945-1

 4  WG secretariat:
------------------------------------------------------------------------
 5  Date circulated by WG secretariat:

 6  Deadline on response from editor:

------------------------------------------------------------------------

 7  Defect Report concerning (number and title of International Standard
    or DIS final text, if applicable): 

Threads Extensions: IEEE Std 1003.1c-1995

------------------------------------------------------------------------ 

 8  Qualifier (e.g. error, omission, clarification required):

1

Error=1 , Omission=2, Clarification=3

------------------------------------------------------------------------ 

 9  References in document (e.g. page, clause, figure, and/or table
    numbers):

POSIX.1-1996, Page 340, clause 16.2.5.2, ll 249

------------------------------------------------------------------------ 

10  Nature of defect (complete, concise explanation of the perceived
    problem):


We believe there is a contradiction in the specification over
requirements for exit status of multi-threaded and non-threaded
processes.

POSIX96 states the following requirement in section 16.2.5.2, page 340,
line 249, pthread_exit():

"The process shall exit with an exit status of 0 after the last thread
has been terminated. The behavior shall be as if the implementation
called exit() with a zero argument at the time of thread termination."


This requirement appears to conflict with the ANSI C standard, section
2.1.2.2, "Program Termination" :

"A return from the initial call to the 'main' function is equivalent 
to calling the 'exit' function with the value returned by the main 
function as it's argument. If the 'main' function executes a return
 that specifies no value, the termination status returned to the host
environment is undefined."

Thus,if any thread calls exit(EXIT_FAILURE) or the main thread calls 
return EXIT_FAILURE, the process is required to terminate with an 
exit status of EXIT_FAILURE by the C standard's exit() 
(section 7.10.4.3) and program termination (section 5.1.2.2.3) 
(and by POSIX.1 and XSH5 exit() and wait() with many values in 
addition to EXIT_SUCCESS and EXIT_FAILURE), but if the process 
was multi-threaded, pthread_exit() requires that every process 
terminate with a zero exit status.

------------------------------------------------------------------------ 

11  Solution proposed by the submitter (optional):


Interpret POSIX.1-1996, P340, L249-251:
		The process shall exit with an exit status of 0 after
		the last thread has been terminated.  The behavior
		shall be as if the implementation called exit() with a
		zero argument at the time of thread termination.
as though it said:
		If the last thread in a process is terminated by a call
		(implicit or explicit) to pthread_exit(), the process
		shall exit with an exit status of 0.  The behavior
		shall be as if the implementation called exit() with a
		zero argument at the time of thread termination.


------------------------------------------------------------------------ 



Interpretation response
-----------------------

The standard clearly states that the process shall exit as if the
implementation called exit() with an argument of zero, after the last
thread in the process has terminated. Conforming implementations must
conform to this.

Investigation of this request has, however, revealed a related
inconsistency in the standard. Section 3.2.1, Wait for Process
Termination, on page 66, lines 376-379, specifies that "If and only if
the status returned is from a terminated child process that returned a
value of zero from main() or passed a value of zero as the status
argument to _exit() or exit(), the value stored at the location pointed
to by stat_loc shall be zero." This statement conflicts with the
requirement that termination of the last thread shall result in process
termination with a value of 0. This inconsistency is being referred to
the sponsor.

Rationale
-------------

There are at least three overlapping issues involved:

  1. A return from the thread that initially calls main() is not a
     "thread termination". Both ANSI C (in the section you have cited)
     and POSIX 1003.1-1996 (16.2.2, pthread_create, page 336, lines
     133-136) clearly state that when the initial thread returns, the
     process terminates. The process exit status is the exit value
     returned from main, or is undefined if no value was explicitly
     returned.
  2. A call to exit() always terminates the process, not a thread.
  3. The fact that a thread once called pthread_exit() within a process
     cannot override a value later passed to exit() or _exit(), or
     returned from main() in the initial thread. The description of
     process exit in POSIX 1003.1-1996 clearly states that the process
     exit status shall be the value passed to exit() or _exit() (or
     returned from main() in the initial thread).

Threads terminate only by returning from the thread start routine (with
the exception of the initial thread), by calling pthread_exit(), or by
cancellation. Unhandled signals, _exit(), exit(), abort(), and return
from main() in the initial thread all result in process termination, and
follow the traditional UNIX rules for process termination. (To have
specified otherwise would break all existing programs.)

All of this left one ambiguity. Because it is possible for all threads,
including the initial thread, to terminate by calling pthread_exit, or
by being cancelled, one could end with a process having no threads,
which could not, ever, under traditional UNIX rules, terminate. The rule
to which this request has referred, that termination of the last thread
shall result in process termination with a value of 0, was devised
solely to address this situation.
------------------------------------------------------------------------ 
12  Editor's response (any material proposed for processing as a
    technical corrigendum to, an amendment to, or a commentary on the
    International Standard or DIS final text is attached separately to
    this completed report):
                                                         
	See interpretation response above

------------------------------------------------------------------------ 

Forwarded to Interpretations group: 1 Feb 1998
Proposed circulation: 11 Feb 1998
Finalised: 11 Mar 1998