Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pthread_self() return a non-zero value in thread_pthread_stubs.h #125161

Closed
colesbury opened this issue Oct 8, 2024 · 2 comments
Closed
Labels

Comments

@colesbury
Copy link
Contributor

colesbury commented Oct 8, 2024

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

@kumaraditya303
Copy link
Contributor

I agree, it's better to fix WASI stubs.

@brettcannon
Copy link
Member

Fine by me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants