linux系统 c语言 多线程
#include<pthread.h>
#include<stdio.h>
#include<unistd.h>
//pthread fun
void *my_th1(void *id){
printf("线程1创建");
while(1){
printf("线程1...\n");
//printf("100ms\n");
usleep(100000);
}
}
void *my_th2(void *id){
printf("线程2创建");
while(1){
printf("线程2...\n");
//printf("100ms\n");
sleep(1);
}
}
int main(){
pthread_t th1,th2;
//creat pthread
if(pthread_create(&th1,NULL,my_th1,NULL)== -1)
printf("线程1创建失败!\n");
if(pthread_create(&th2,NULL,my_th2,NULL)== -1)
printf("线程2创建失败!\n");
//wait pthread
pthread_join(th1,NULL);
pthread_join(th2,NULL);
}