古詩詞大全網 - 成語解釋 - pthreadt

pthreadt

#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());

}