-
-
Save nebkor/34494a3fdd68fd23d959fa72bd219dbe to your computer and use it in GitHub Desktop.
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 <pthread.h> | |
#include <unistd.h> | |
void *work(void *arg) { | |
printf("Sleeping for %d seconds.\n", *(int *) arg); | |
sleep(*(uint *) arg); | |
printf("%d\n", *(int*) arg); | |
return arg; | |
} | |
int main() { | |
pthread_t t1, t2; | |
int magic_nr_1 = 46; | |
int magic_nr_2 = 3; | |
pthread_create(&t1, NULL, work, (void *) &magic_nr_1); | |
pthread_create(&t2, NULL, work, (void *) &magic_nr_2); | |
pthread_join(t1,NULL); | |
pthread_join(t2,NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has the correct name for the thread worker function, as well as the correct casting for the arguments to the work function.