A NOTE has been added to this issue. ====================================================================== https://austingroupbugs.net/view.php?id=792 ====================================================================== Reported By: eblake Assigned To: ====================================================================== Project: 1003.1(2013)/Issue7+TC1 Issue ID: 792 Category: Base Definitions and Headers Type: Omission Severity: Objection Priority: normal Status: New Name: Eric Blake Organization: Red Hat User Reference: ebb.thread_lifetime Section: 3.399 Thread ID Page Number: 97 Line Number: 2704 Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2013-11-15 05:23 UTC Last Modified: 2022-08-02 14:53 UTC ====================================================================== Summary: better definition of thread lifetime ====================================================================== Relationships ID Summary ---------------------------------------------------------------------- related to 0000765 kill and pthread_kill behavior between ... related to 0000690 clarify behavior when calling waitpid w... ======================================================================
---------------------------------------------------------------------- (0005923) geoffclare (manager) - 2022-08-02 14:53 https://austingroupbugs.net/view.php?id=792#c5923 ---------------------------------------------------------------------- The following is the desired action with a few wording changes based on the email discussion in Nov 2013 and some updates to include C17 threads. Page and line numbers have been updated to be for Issue 8 draft 2.1. [Editor's Note: This adds several new definition sections. Make sure that the additions remain in sorted order, and that all sections are numbered appropriately afterwards. I sorted "Thread Termination" before "Thread-Safe" based on the existing precedence of "Priority Scheduling" before "Priority-Based Scheduling". The remainder of this request refers only to existing D2.1 section numbering and references to new section names.] After XBD section 3.177 ("Job Control Job ID") page 54 line 1718, insert a new section <b>Joinable Thread</b> with the following contents:<blockquote>A thread that was created either using <i>pthread_create</i>() with the <i>detachstate</i> attribute not set to PTHREAD_CREATE_DETACHED or using <i>thrd_create</i>(), and for which neither <i>pthread_detach</i>() nor <i>pthread_join</i>() has been called and returned zero, and neither <i>thrd_detach</i>() nor <i>thrd_join</i>() has been called and returned <tt>thrd_success</tt>. <small><b>Note:</b> The <i>pthread_attr_setdetachstate</i>(), <i>pthread_create</i>(), <i>pthread_detach</i>(), <i>pthread_join</i>(), <i>thrd_create</i>(), <i>thrd_detach</i>(), and <i>thrd_join</i>() functions are defined in detail in the System Interfaces volume of POSIX.1-202x.</small></blockquote> After XBD section 3.183 ("Live Process") page 55 line 1738, insert a new section <b>Live Thread</b> with the following contents (copied from the existing text at 3.372 Thread, with two minor changes):<blockquote>A single flow of control within a process. Each thread has its own thread ID, scheduling priority and policy, <i>errno</i> value, floating point environment, thread-specific key/value bindings, and the required system resources to support a flow of control. Anything whose address can be determined by a thread, including but not limited to static variables, storage obtained via <i>malloc</i>(), directly addressable storage obtained through implementation-defined functions, and automatic variables, are accessible to all live threads in the same process. <small><b>Note:</b> The <i>malloc</i>() function is defined in detail in the System Interfaces volume of POSIX.1-202x.</small></blockquote> At XBD section 3.372 ("Thread") page 82 line 2490, change:<blockquote>A single flow of control within a process. Each thread has its own thread ID, scheduling priority and policy, <i>errno</i> value, floating point environment, thread-specific key/value bindings, and the required system resources to support a flow of control. Anything whose address may be determined by a thread, including but not limited to static variables, storage obtained via <i>malloc</i>(), directly addressable storage obtained through implementation-defined functions, and automatic variables, are accessible to all live threads in the same process. <small><b>Note:</b> The <i>malloc</i>() function is defined in detail in the System Interfaces volume of POSIX.1-202x.</small></blockquote>to:<blockquote>A live thread (see [xref to Live Thread]) or a zombie thread (see [xref to Zombie Thread]). The lifetime of a thread is described in [xref to Thread Lifetime].</blockquote> After XBD section 3.373 ("Thread ID") page 82 line 2499, insert a new section <b>Thread Lifetime</b> with contents:<blockquote>The period of time that begins when a thread is created and ends when its thread ID is returned to the process. See also <i>Live Thread</i> in [xref to Live Thread], <i>Thread Termination</i> in [xref to Thread Termination], and <i>Zombie Thread</i> in [xref to Zombie Thread]. <small><b>Note:</b> Thread creation is defined in detail in the descriptions of the <i>pthread_create</i>() and <i>thrd_create</i>() functions in the System Interfaces volume of POSIX.1-202x.</small></blockquote> After XBD section 3.374 ("Thread List") page 82 line 2503, insert a new section <b>Thread Termination</b> with contents:<blockquote>Thread termination occurs when a thread executes <i>pthread_exit</i>() or <i>thrd_exit</i>(), when it returns from the <i>start_routine</i> function passed to <i>pthread_create</i>() or from the <i>func</i> function passed to <i>thrd_create</i>(), or when it acts on a cancellation request initiated by <i>pthread_cancel</i>(). <small><b>Note:</b> The <i>pthread_cancel</i>(), <i>pthread_create</i>(), <i>pthread_exit</i>(), <i>thrd_create</i>(), and <i>thrd_exit</i>() functions are defined in detail in the System Interfaces volume of POSIX.1-202x.</small></blockquote> After XBD section 3.408 ("Zombie Process") page 87 line 2638, add a new section <b>Zombie Thread</b> with contents:<blockquote>The remains of a joinable live thread (see [xref to Joinable Thread] and [xref to Live Thread]) after it terminates (see [xref to Thread Termination]) and before it has been joined with <i>pthread_join</i>() or <i>thrd_join</i>() or detached with <i>pthread_detach</i>() or <i>thrd_detach</i>(). <small><b>Note:</b> The <i>pthread_detach</i>(), <i>pthread_join</i>(), <i>thrd_detach</i>(), and <i>thrd_join</i>() functions are defined in detail in the System Interfaces volume of POSIX.1-202x.</small></blockquote> At XSH section 2.9.2 ("Thread IDs") page 501 line 17748, after applying bug 1302, change:<blockquote>The lifetime of a thread ID ends after the thread terminates if it was created using <i>pthread_create</i>() with the <i>detachstate</i> attribute set to PTHREAD_CREATE_DETACHED or if <i>pthread_detach</i>(), <i>pthread_join</i>(), <i>thrd_detach</i>(), or <i>thrd_join</i>() has been called for that thread.</blockquote>to:<blockquote>The lifetime of a thread ID ends after the later of thread termination (see [xref to Thread Termination]) and the point when the thread is no longer joinable (see [xref to Joinable Thread]).</blockquote> At XSH pthread_cancel page 1553 line 51305 (DESCRIPTION), add a new sentence:<blockquote>It shall not be an error to request cancellation of a zombie thread.</blockquote> After XSH pthread_cancel page 1553 line 51340 (RATIONALE), add a new paragraph:<blockquote>Historical implementations varied on the result of a <i>pthread_cancel</i>() with a thread ID indicating a zombie thread. Some indicated success with nothing further to do because the thread had already terminated, while others gave an error of [ESRCH]. Since the definition of thread lifetime in this standard covers zombie threads, the [ESRCH] error as described is inappropriate in this case and implementations that give this error do not conform.</blockquote> At XSH pthread_detach page 1587 line 52443 (DESCRIPTION), change:<blockquote>If <i>thread</i> has not terminated, <i>pthread_detach</i>() shall not cause it to terminate.</blockquote>to:<blockquote>If <i>thread</i> has not terminated, <i>pthread_detach</i>() shall not cause it to terminate, but shall prevent the thread from becoming a zombie thread when it does terminate.</blockquote> At XSH pthread_join page 1598 line 52801 (DESCRIPTION), change:<blockquote>a thread that has exited but remains unjoined</blockquote>to:<blockquote>a zombie thread</blockquote> At XSH pthread_kill page 1606 line 53102 (DESCRIPTION), add a sentence:<blockquote>It shall not be an error if <i>thread</i> is a zombie thread.</blockquote> At XSH pthread_kill page 1606 line 53124 (RATIONALE), change:<blockquote>Existing implementations vary on the result of a <i>pthread_kill</i>() with a thread ID indicating an inactive thread (a terminated thread that has not been detached or joined). Some indicate success on such a call, while others give an error of [ESRCH]. Since the definition of thread lifetime in this volume of POSIX.1-202x covers inactive threads, the [ESRCH] error as described is inappropriate in this case.</blockquote>to:<blockquote>Historical implementations varied on the result of a <i>pthread_kill</i>() with a thread ID indicating a zombie thread. Some indicated success on such a call, while others gave an error of [ESRCH]. Since the definition of thread lifetime in this volume of POSIX.1-202x covers zombie threads, the [ESRCH] error as described is inappropriate in this case and implementations that give this error do not conform.</blockquote> At XSH pthread_kill page 1606 line 53132 (FUTURE DIRECTIONS), change:<blockquote>A future version of this standard may require that <i>pthread_kill</i>() not fail with [ESRCH] in the case of sending signals to an inactive thread (a terminated thread not yet detached or joined), even though no signal will be delivered because the thread is no longer running.</blockquote>to:<blockquote>None.</blockquote> Issue History Date Modified Username Field Change ====================================================================== 2013-11-15 05:23 eblake New Issue 2013-11-15 05:23 eblake Name => Eric Blake 2013-11-15 05:23 eblake Organization => Red Hat 2013-11-15 05:23 eblake User Reference => ebb.thread_lifetime 2013-11-15 05:23 eblake Section => 3.399 Thread ID 2013-11-15 05:23 eblake Page Number => 97 2013-11-15 05:23 eblake Line Number => 2704 2013-11-15 05:23 eblake Interp Status => --- 2013-11-15 05:23 eblake Tag Attached: issue8 2013-11-15 05:23 eblake Relationship added related to 0000765 2013-11-15 05:24 eblake Relationship added related to 0000690 2013-11-15 05:29 eblake Desired Action Updated 2019-05-23 16:08 geoffclare Tag Detached: issue8 2022-08-02 14:53 geoffclare Note Added: 0005923 ======================================================================