23,114
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void thread(void){
int j;
for(j = 0; j<3; j++){
//printf("This is %d pthread.\n", i);
printf("This is a pthread.\n");
}
pthread_exit(0);
}
int main(void){
pthread_t id;
int i, ret;
ret = pthread_create(&id, NULL, (void *)thread, NULL);
if(ret != 0){
printf("Create a thread error!\n");
exit(1);
}
for(i = 0; i < 3; i++){
printf("This is the main process.\n");
}
//pthread_join(id, NULL);
return 0;
}
This is the main process.
This is the main process.
This is the main process.
This is a pthread.
This is a pthread.
This is a pthread.
This is a pthread.
while (true); do ./a.out; date; done > kk
cat kk | more