发布网友 发布时间:2022-05-02 23:02
共1个回答
热心网友 时间:2022-05-13 21:29
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
#define THREAD_NUM 3
void * thread_handler(void *arg);
void main()
{
int i;
pthread_t tid[THREAD_NUM];
for(i = 0; i < THREAD_NUM; i++){
pthread_create(&tid[i], NULL, thread_handler, NULL);
}
for(i = 0; i < THREAD_NUM; i++){
pthread_join(tid[i],NULL);
}
}
void * thread_handler(void *arg)
{
printf("process id: %d\tthread id: %lu\n", getpid(),pthread_self());
}