Date: 08 Mar 2003 05:55:58 -0500 From: Aaron Walker <ka0ttic@cfl.rr.com> To: freebsd-questions@freebsd.org Subject: undefined reference to 'pthread_detach' Message-ID: <1047120959.3805.4.camel@ka0ttic>
next in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1047120959.3805.4.camel>
