FreeBSD pthread_equal "bug"

Kern Sibbald kern at sibbald.com
Wed Jun 4 05:38:48 PDT 2003


Hello,

I've run into what I consider a bug in the FreeBSD 
implementation of pthreads and pthread_equal() in
particular.  Basically, pthread_equal() will return
true even if it is not the same thread.  This can occur
when one thread dies and another one starts. The second
thread then takes on the exact identity of the the
first thread, and pthread_equal() returns true for a
case where it is a different thread.  You may argue
that the first thread is dead so its thread id is no
longer valid. True, but think about how Unix would
work if every process started up with the process
id of the last process to exit.

Even if someone were to claim that this case is 
undefined, I would say fine, but it is rather trivial
to ensure that pthread_equal() returns false unless
the thread is really physically the same thread,
you just need one variable in pthread_t that is
incremented for each new thread, so why not do it
"the right way".

This bug exists in the FreeBSD implementation but
not in Linux or in Solaris.

I've worked around the bug so this is not a critical
issue for me.

I've attached a simple program that illustrates this
problem. Don't hesitate to ask if you have any questions,
but please be aware that I am not subscribed to the
list.

Best regards,

Kern
Switzerland


More information about the freebsd-threads mailing list