Created
October 2, 2022 01:49
-
-
Save pwnwriter/4c59363a2bd30ab87885fb92501d6b11 to your computer and use it in GitHub Desktop.
// multithreading example in c !
This file contains 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
#include <stdio.h> | |
#include <pthread.h> | |
#define THREAD_NUM 5 | |
void * workerThreadFunc(void *tid){ | |
char buf[35]; | |
long * myID = (long *) tid; | |
printf("Hello world this is thread no. %ld\n", *myID); | |
} | |
int main(void){ | |
pthread_t tid[THREAD_NUM]; | |
pthread_t * pthreads[] = {&tid[0],&tid[1],&tid[2],&tid[3],&tid[4],&tid[5]}; | |
for (int i = 0; i < THREAD_NUM; i++){ | |
pthread_create(pthreads[i],NULL,workerThreadFunc,(void *)pthreads[i]); | |
} | |
pthread_exit(NULL); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment