#include <stdio.h>
#include <pthread.h>
// 以下是两个线程函数,它们分别在无限循环中输出不同的信息。
void* func1()
{
while(1){
printf("this is func 1\n");
sleep(1); // 线程休眠1秒
}
}
void* func2()
{
while(1){
printf("this is func 2\n");
sleep(1); // 线程休眠1秒
}
}
int main()
{
pthread_t th1; // 创建线程1的标识符
pthread_t th2; // 创建线程2的标识符
pthread_create(&th1, NULL, func1, NULL); // 创建线程1,将其与func1函数关联
pthread_create(&th2, NULL, func2, NULL); // 创建线程2,将其与func2函数关联
while(1); // 主线程无限循环,以保持程序运行
return 0;
}