Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jun 2003 09:52:07 -0400
From:      Mike Makonnen <mtm@identd.net>
To:        Kern Sibbald <kern@sibbald.com>
Cc:        freebsd-threads@freebsd.org
Subject:   Re: FreeBSD pthread_equal "bug"
Message-ID:  <20030604135208.LPAG20810.pop015.verizon.net@kokeb.ambesa.net>
In-Reply-To: <1054730325.13630.456.camel@rufus>
References:  <1054730325.13630.456.camel@rufus>

next in thread | previous in thread | raw e-mail | index | archive | help

>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@identd.net | D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
mtm@FreeBSD.Org| FreeBSD - The Power To Serve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030604135208.LPAG20810.pop015.verizon.net>