Skip to content

Instantly share code, notes, and snippets.

@pwnwriter
Created October 2, 2022 01:49
Show Gist options
  • Save pwnwriter/4c59363a2bd30ab87885fb92501d6b11 to your computer and use it in GitHub Desktop.
Save pwnwriter/4c59363a2bd30ab87885fb92501d6b11 to your computer and use it in GitHub Desktop.
// multithreading example in c !
#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