How do I get a thread ID from an arbitrary pthread_t?

Since pthreads do not need to be implemented with Linux threads (or kernel threads at all, for that matter), and some implementations are entirely user-level or mixed, the pthreads interface does not provide functions to access these implementation details, as those would not be portable (even across pthreads implementations on Linux). Thread libraries that use … Read more

How do you declare a recursive mutex with POSIX threads?

The code from Michael Foukarakis is almost good but he initializes the mutex twice which leads to undefined behavior. It should just be: pthread_mutex_t Mutex; pthread_mutexattr_t Attr; pthread_mutexattr_init(&Attr); pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&Mutex, &Attr); I actually use this code in production, and I know it works correctly on Linux, Solaris, HP-UX, AIX, Mac OSX and FreeBSD. You … Read more

Green-threads and thread in Python

You can think of greenlets more like cooperative threads. What this means is that there is no scheduler pre-emptively switching between your threads at any given moment – instead your greenlets voluntarily/explicitly give up control to one another at specified points in your code. Does the GIL affect them? Can there be more than one … Read more