C语言中线程函数
1.pthread_t thread创建线程号
2.void *start_routine(void *arg) 线程函数
3.头文件的调用
#include <pthread.h>
#include <unistd.h>
4.代码运行样例:
11111
22222
11111
22222
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *start_routine(void *arg)
{
while(1)
{
sleep(1);
printf("11111\n");
}
}
int main()
{
pthread_t thread=0;
pthread_create(&thread, NULL,start_routine, NULL);
while(1)
{
sleep(2);
printf("22222\n");
}
}