Skip to content

Instantly share code, notes, and snippets.

@ishankhare07
Created April 1, 2018 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishankhare07/8d5befbeb5e698d9d8623474497aa17e to your computer and use it in GitHub Desktop.
Save ishankhare07/8d5befbeb5e698d9d8623474497aa17e to your computer and use it in GitHub Desktop.
create threads and wait using join
#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;
}
@ishankhare07
Copy link
Author

compile it with

gcc -Wall -pthread create_threads.c -o create_threads
./create_threads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment