#include<stdlib.h>
#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>
#include<linux/unistd.h>
#include<errno.h>
void thread(void)
{int i =0;
for(i=0;i<3;i++){
printf("this is a pthread.\n");
sleep(1);
}
}
int main(void)
{pthread_t id;
int i, ret;
ret=pthread_create(&id,NULL,(void *)thread,NULL);
if(ret!=0){
printf("Create pthread error!\n");
exit(1);
}
for(i=0;i<3;i++){
printf("this is the main process.\n");
sleep(1);
}
pthread_join(id,NULL);
return(0);
}
关键是编译为 gcc -o pthread_test pthread_test.c -lpthread
最后./ pthread_test