I was writing a little test threads program, and when I try to compile I
get this:

<ka0ttic :~/code>$gcc -o mttest mttest.c -lpthread
/tmp/cco18ppz.o: In function `thread_func':
/tmp/cco18ppz.o(.text+0xd2): undefined reference to `pthread_detach'

I don't understand why I am getting this since pthread.h is included and
I am including the library when compiling.  the code is below.. any one
have any ideas?

here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#define _REENTRANT
#define _POSIX_SOURCE

void * thread_func(void *);

int main(int argc, char **argv)
{
  int i, r, n, nthreads;
  pthread_t t;

  if(argc != 2) {
    fprintf(stderr, "argc != 2\n");
    exit(1);
  }

  n = atoi(argv[1]);
  nthreads = 0;

  for(i=0;i<n;i++) {
    r = pthread_create(&t, NULL, &thread_func, NULL);
    if(r == 0)
      nthreads++;
  }

  printf("%d out of %s threads created.\n", nthreads, argv[1]);
  sleep(10);
  return 0;
}

void *thread_func(void *null)
{
  int i;

  pthread_detach(pthread_self());

  for(i=0; i <10000;i++)
    ;
}

--
Thanks,
Aaron



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-questions" in the body of the message

Reply via email to