Cannot get pthread_getspecific to work on FreeBSD

Hi,

I have trouble setting a thread specific variable with the pthread API on FreeBSD (I am resorting to pthread because Clang does not seem to support gcc's __thread specifier)

A sample program like:

Code:
#include <pthread.h>
#include <stdio.h>

pthread_key_t   tlsKey = 0;

int main(int argc, char **argv)
{
  int tls;

  pthread_key_create(&tlsKey, NULL);
  pthread_setspecific(tlsKey, 24);
  tls = pthread_getspecific(tlsKey);
  printf("Got %d\n", tls);
  return 0;
}

would print 24 on Linux and OS X, but 0 on FreeBSD (8.2-RELEASE-p3)

I am sure that I am misusing the pthread API, but I could use some help in identifying the problem.

Thanks in advance,
- Philippe
 
Back
Top