tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pthread_setname_np API is bad



My recent commit [0] in Mesa spawned a discussion [1] about why
pthread_setname_np()'s parameter 'void *args' is not 'const void *args'.

Looking in your CVS history, I see that pthread_setname_np() and friends
were added in 2003 and claim to use an API compatible with Tru64 UNIX
API. I find this bizarre and misguided because even in 2003 it was clear that Tru64's future was grim, and also the API is *not* compatible with Tru64 since their third argument is
named 'mbz' -- must be zero!

Worse it's incompatible from that of FreeBSD, OpenBSD, and glibc in a
useless way. NetBSD made use of the third argument as a single parameter
to feed to snprintf(). Callers can just do that themselves, and then
projects like Mesa wouldn't have to special case NetBSD in at least this
place...

So great, you made your API incompatible with everyone else for zero
gain. /o\

But short of removing the unnecessary third argument (which is a great
idea IMO), can I suggest that you at least set the type to 'const void
*' instead of 'void *'? Callers would then be able to call
pthread_setname_np(..., "%s", name) without the silly cast of "name" [3]
which is going to be a const char * as every other platform expects.
Evidently others have run into this same problem as well [4].

I suggested this to kamil@ in [1] but he doesn't seem to believe me
(???) that you can pass non-const-qualified pointers as const-qualified
parameters with no ill effects.

[0] https://cgit.freedesktop.org/mesa/mesa/commit/?id=dcf9d91a80ee76f46e162afef9bd1b2ddb53ecc3
[1] https://github.com/mesa3d/mesa/commit/dcf9d91a80ee76f46e162afef9bd1b2ddb53ecc3#commitcomment-34556150
[2] https://github.com/NetBSD/src/commit/917ff110b292645f8c682fc81c33b8b03a54f06d
[3] https://cgit.freedesktop.org/mesa/mesa/commit/?id=2fd30e37220484f44b1cfb1ee9afbe6c8a0b43f0
[4] https://github.com/mpv-player/mpv/issues/1207

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index