Skip to content

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

@colesbury

Description

@colesbury

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions