The C11 support to thread is fine but not exaustive. In case I need to use pthread functions, I would like to understand if it is legal to cast thrd_t
to pthread_t
. For example:
#include <threads.h>
#define_GNU_SOURCE
#include <pthread.h>
#include <sched.h>
int main(void) {
thrd_t t;
cpu_set_t cpuset;
// some initialization code here...
pthread_setaffinity_np((pthread_t)t, sizeof(cpuset), &cpuset) // Is the cast valid?
// other code here...
}
C++11 provides std::thread::native_handle to get the pthread_t
value to be in pthread functions, but C11 does not provide such function. Since, both thrd_t
and pthread_t
are typedefs to unsigned long int
, I suppose they are compatible. What does the standard say about it?
Edit: the same question applies also for the other two types provided by threads.h
, i.e. mtx_t
and cnd_t
.