-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
Description
Currently our stub for pthread_self()
(used by WASI) just returns zero:
cpython/Python/thread_pthread_stubs.h
Lines 106 to 109 in 37228bd
PyAPI_FUNC(pthread_t) pthread_self(void) | |
{ | |
return 0; | |
} |
I propose we return a non-zero value for better consistency with functional pthread implementations. For example:
PyAPI_FUNC(pthread_t) pthread_self(void)
{
return (pthread_t)(uintptr_t)&py_tls_entries;
}
Why?
We occasionally assume that PyThread_get_thread_ident_ex()
returns a non-zero value. For example:
- Thread ID assertion in
pystate.c
failing under WASI #110455 - In
_PyRecursiveMutex
for the owner field (oops)
We can work around these issues with #ifndef HAVE_PTHREAD_STUBS
or by fixing the _PyRecursiveMutex
implementation, but I think we might save ourselves a few headaches in the future by just making the pthread_self()
stub behave a bit more like actual pthread implementations.
cc @brettcannon @kumaraditya303