bpo-36084: add native thread ID (TID) to threading.Thread objects by jaketesler · Pull Request #11993 · python/cpython (original) (raw)
From @pitrou
On POSIX platforms, pthread_create returns the thread ID
Where is that? According to POSIX, "If successful, the pthread_create() function shall return zero; otherwise, an error number shall be returned to indicate the error."
All –
pthread_create
- create a new thread
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
...
Seepthread_self(3)
for further information on the thread ID returned
in*thread
bypthread_create()
. Unless real-time scheduling policies
are being employed, after a call topthread_create()
, it is
indeterminate which thread—the caller or the new thread—will next
execute.Source: man7.org
To clarify, the ID returned via the first argument in the call to pthread_create()
, which is also the same value as the Python ident
attribute, is the same value as returned by a call to pthread_self()
.
This is not the same identifier as the one created by pthread_getthreadid_np()
, et al. This value is the one identifying a particular thread to the kernel – the value is an integral, native system identifier, e.g. as reported by system monitoring utilities or accessed in debuggers.