Hi, in uv-common.c:

unsigned long uv_thread_self(void) {
#ifdef _WIN32
  return (unsigned long) GetCurrentThreadId();
#else
  return (unsigned long) pthread_self();
#endif
}


According to pthread_self() the returned value has type pthread_t
which is not specified:

http://man7.org/linux/man-pages/man3/pthread_self.3.html

       POSIX.1 allows an implementation wide freedom in choosing the type
       used to represent a thread ID; for example, representation using
       either an arithmetic type or a structure is permitted.  Therefore,
       variables of type pthread_t can't portably be compared using the C
       equality operator (==); use pthread_equal(3) instead.

       Thread identifiers should be considered opaque: any attempt to use a
       thread ID other than in pthreads calls is nonportable and can lead to
       unspecified results.

       Thread IDs are guaranteed to be unique only within a process.  A
       thread ID may be reused after a terminated thread has been joined, or
       a detached thread has terminated.

       The thread ID returned by pthread_self() is not the same thing as the
       kernel thread ID returned by a call to gettid(2).


So how safe (or portable) is the (unsigned long) pthread_self() line
above? If for example the implementation decides to use a struct for
the pthread_t type, the above cast would fail to compile.


Regards.


-- 
Iñaki Baz Castillo
<[email protected]>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to