Created
April 8, 2018 13:57
-
-
Save tarunjain07/b6d0c616d07c2d6bb10c185e30a390cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A Slightly Less Simple PThreads Example */ | |
#include <stdio.h> | |
#include <pthread.h> | |
#define NUM_THREADS 4 | |
void *threadFunc(void *pArg) { /* thread main */ | |
int *p = (int*)pArg; | |
int myNum = *p; | |
printf("Thread number %d\n", myNum); | |
return 0; | |
} | |
int main(void) { | |
int i; | |
pthread_t tid[NUM_THREADS]; | |
for(i = 0; i < NUM_THREADS; i++) { /* create/fork threads */ | |
pthread_create(&tid[i], NULL, threadFunc, &i); | |
} | |
for(i = 0; i < NUM_THREADS; i++) { /* wait/join threads */ | |
pthread_join(tid[i], NULL); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment