Created
April 1, 2018 20:14
-
-
Save ishankhare07/8d5befbeb5e698d9d8623474497aa17e to your computer and use it in GitHub Desktop.
create threads and wait using join
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
#include "stdio.h" | |
#include "assert.h" | |
#include "pthread.h" | |
void *myThread(void *arg) { | |
printf("%s\n", (char *) arg); | |
return NULL; | |
} | |
int main() { | |
pthread_t p1, p2; | |
int rc; | |
rc = pthread_create(&p1, NULL, myThread, "A"); assert(rc == 0); | |
rc = pthread_create(&p2, NULL, myThread, "B"); assert(rc == 0); | |
rc = pthread_join(p1, NULL); assert(rc == 0); | |
rc = pthread_join(p2, NULL); assert(rc == 0); | |
printf("main: end\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
compile it with