-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
On 04/02/2014 12:36 PM, Iñaki Baz Castillo wrote:
> 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.
>
Not sure why it's implemented like this, so I cannot comment on that.
We could have a uv_thread_id_t opaque struct (union really) which
stored both Windows and Unix representations, and have a
uv_thread_compare function that does the equivalent of pthread_compare.
Can you open an issue on GH? Also, patches are always welcome :-)
- --
Saúl Ibarra Corretgé
bettercallsaghul.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/
iQIcBAEBAgAGBQJTO+qpAAoJEEEOVVOum8BZLecP/2VRtcaNaJwfix/ykk2FFQgU
+9bsWZBA67cygMtGMwlp83vALU4WtIDced/Vq/3RGIe6S8qfETZmFF4nFdgSME9c
id49AIbHsJ9AqnchL0uCII+pYRnnH8uf0V9fIC4mC46i8SCBXcjhuoEn/keicufF
csWbwB+aM5l8JL28wap4JVcerqw9e+mR1bHp4lWl7CHp7XB/Un3tTrgKgt3XXfaJ
2l07dmVrLGs9KmTsBOvi+zaHqt4MDTPcXQUz1vmyThsgrMs67dAA+s+CRJFRKoTv
kEw5i4jvIw0vuKH72tkF/ftCciSKZkm2FWtBZ2GzeMc5WwdU6DAp78aMhhq2TJfk
AF13sAUj1XRoLYhj5ZrHNBfN1ciuKVUd1DusJN+OdFP+ddK/NYFMkemfY71ZftU0
jLO3z+GgOl5tSy9yZnxjdEGZFVYoqIE9nqnNEsCye0HTatP3ZKgnLgB3LMuO34Mj
Oo7+prYiADKapMkB7SD4jxQXaVE7NqVNfo1VClfjrZRcBGefPiDe7wFGMev21gS4
hd3yZtyyXmNlb7k8XqqD7mAjQkAqVNXGBmySy9L7HPi2miw96Ge1Ly5N474E8AJQ
wcU3vCJiuHQ6RL4v7UJ8kgyfCapmPgID54bpw6RcIz4o1Y+lfApFj2397s57E/Xg
Lgcdm0ZGMRSsHuN/5St3
=pDRR
-----END PGP SIGNATURE-----
--
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.