Assorted code in the Python core supposes that the result of pthread_self() cannot be equal to PYTHREAD_INVALID_THREAD_ID, ie (void *) -1. If it is, you get a crash at interpreter startup. Unfortunately, this supposition is directly contrary to the POSIX specification for pthread_self(), which defines no failure return value; and it is violated by NetBSD's implementation in some circumstances. In particular, we (the Postgres project) are observing that libpython.so fails when dynamically loaded into a host executable that does not itself link libpthread. NetBSD's code always returns -1 if libpthread was not present at main program start, as they do not support forking new threads in that case. They assert (and I can't disagree) that their implementation conforms to POSIX.
A lazy man's solution might be to change PYTHREAD_INVALID_THREAD_ID to some other value like -3, but that's not fixing the core problem that you're violating POSIX by testing for any specific value at all.
Details and background info can be found in this email thread:
1560896200%40sss.pgh.pa.us">https://www.postgresql.org/message-id/flat/25662.1560896200%40sss.pgh.pa.us
|