FreeBSD pthread_equal "bug"

Mike Makonnen mtm at identd.net
Wed Jun 4 06:52:09 PDT 2003


>From the new linux NPTL:
=================
typedef struct __opaque_pthread *pthread_t;
int
__pthread_equal (thread1, thread2)
     pthread_t thread1;
     pthread_t thread2;
{
  return thread1 == thread2;
}
strong_alias (__pthread_equal, pthread_equal)


>From FreeBSD's libc_r implementation:
==========================
typedef struct  pthread                 *pthread_t;
__weak_reference(_pthread_equal, pthread_equal);

int
_pthread_equal(pthread_t t1, pthread_t t2)
{
        /* Compare the two thread pointers: */
        return (t1 == t2);
}

In both implementations pthread_t is a pointer to a memory location.
So, your inability to reproduce this on Linux is probably an accident and not an
intentional feature.

If the two threads (i.e. the dead one and the new one point to the same memory
location using unique id's is not going to solve the problem because both
pointers will be pointing to the same structure (and therefore the same unique
id, even though it will be a different id after the second thread is created).

The only fool-proof way to do this is to make pthread_t a proper structure
containing a unique id and a pointer to a thread structure, but that would mean
passing a structure on the stack (which is not necessarily bad in itself,
but means someone would have to go through all the threads libraries and
modify appropriately). 
On the other hand I may be mistaken and there may be an easy way to achieve
this :-)

Cheers.
-- 
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
mtm at FreeBSD.Org| FreeBSD - The Power To Serve


More information about the freebsd-threads mailing list