Currently our stub for pthread_self() (used by WASI) just returns zero:
|
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:
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
Linked PRs
Currently our stub for
pthread_self()(used by WASI) just returns zero:cpython/Python/thread_pthread_stubs.h
Lines 106 to 109 in 37228bd
I propose we return a non-zero value for better consistency with functional pthread implementations. For example:
Why?
We occasionally assume that
PyThread_get_thread_ident_ex()returns a non-zero value. For example:pystate.cfailing under WASI #110455_PyRecursiveMutexfor the owner field (oops)We can work around these issues with
#ifndef HAVE_PTHREAD_STUBSor by fixing the_PyRecursiveMuteximplementation, but I think we might save ourselves a few headaches in the future by just making thepthread_self()stub behave a bit more like actual pthread implementations.cc @brettcannon @kumaraditya303
Linked PRs