linux 线程相关
编译加上参数
gcc -lpthread
--------------1.1第一个线程---
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
int * thread(void *arg)
{
printf("thread id is %d.\n",pthread_self());
return NULL;
}
int main()
{
pthread_t id;
printf("Main thread id is %d \n",pthread_self());
if(!pthread_create(&id,NULL,(void *)thread,NULL))
{
printf("succeed!\n");
return 0;
}
else
{
printf("Fail to Create Thread");
return -1;
}
-----------1.1 end ------

浙公网安备 33010602011771号