|
|
这是APUE 上的一个关于pthread的程序.可是我编译时gcc提示
phtread_create 未定义,可是pthread.h加了的吗!?也有 /usr/include/pthread.h 这个头文件!请路过的朋友能看看呀!3q!
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
pthread_t ntid;
static void printids(char *);
static void *thr_fn(void *);
int
main(void)
{
int err;
err = pthread_create (&ntid, NULL,thr_fn, NULL);
if (err != 0)
printf ("ptherd_create error \n");
printids ("main thread: ");
sleep (1);
exit (0);
}
void printids(char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid ();
tid = pthread_self ();
printf ("%s pid %u tid %u (0x%x)\n",
s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}
void *thr_fn(void *arg)
{
printids ("new thread: ");
return ((void *)0);
} |
|