N1750 – Implicit thrd_exit
WG 14 Document: N1750
Submitter: Aaron Ballman (US)
Submission Date: 2013年08月29日
Source:
Reference Document:
Version: 1.0
Date: Aug 2013
Subject: Implicit
thrd_exit()
Summary
Currently, when exiting a thread's thrd_start_t
function by returning from it, the behavior is unspecified.
This ambiguity in the standard could be argued to imply the
only way to saefly exit a thread is via a call to
thrd_exit(). For example:
int thread_func(void *arg) {
/* Perform work */
thrd_exit(12);
}
However, the implied behavior of return a value
from the thrd_start_t function is that the thread is
terminated as though the user had called thrd_exit(),
passing in the value returned from the function.
Suggested Change
7.26.5.1p2, change:
The thrd_create function creates a new thread
executing func(arg). If the thrd_create
function succeeds, it sets the object pointed to by
thr to the identifier of the newly created thread.
(A thread's identifier may be reused for a different thread
once the original thread has exited and either been detached
or joined to another thread.) The completion of the
thrd_create function synchronizes with the beginning
of the execution of the new thread.
to
The thrd_create function creates a new thread
executing func(arg). If execution of
func(arg) is terminated via a return statement, the
thread is terminated as though through a call to
thrd_exit. If the thrd_create function
succeeds, it sets the object pointed to by thr to
the identifier of the newly created thread. (A thread's
identifier may be reused for a different thread once the
original thread has exited and either been detached or joined
to another thread.) The completion of the thrd_create
function synchronizes with the beginning of the execution of
the new thread.