Make some fixups to POSIX threads

This commit is contained in:
Justine Tunney 2022-09-07 21:13:50 -07:00
parent de511bc71a
commit 6c323383e5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 168 additions and 69 deletions

View file

@ -24,10 +24,22 @@
/**
* Terminates current POSIX thread.
*
* If this function is called from the main thread, or a thread created
* with clone() or _spawn(), then this function is the same as _Exit1()
* in which case `rc` is coerced to a `uint8_t` exit status, which will
* only be reported to the parent process on Linux, FreeBSD and Windows
*
* @param rc is reported later to pthread_join()
* @threadsafe
* @noreturn
*/
void pthread_exit(void *rc) {
wontreturn void pthread_exit(void *rc) {
struct PosixThread *pt;
pt = ((cthread_t)__get_tls())->pthread;
pt->rc = rc;
longjmp(pt->exiter, 1);
if ((pt = ((cthread_t)__get_tls())->pthread)) {
pt->rc = rc;
longjmp(pt->exiter, 1);
} else {
_Exit1((int)(intptr_t)rc);
}
}