Last active
March 10, 2016 19:58
-
-
Save madbence/f2d99e4acfac26bbd136 to your computer and use it in GitHub Desktop.
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 <stdlib.h> | |
| #include <pthread.h> | |
| void* run(void *arg) { | |
| printf("hello from %d!\n", *(int*)arg); | |
| pthread_exit(NULL); | |
| } | |
| int main() { | |
| int ids[4]; | |
| pthread_t threads[4]; | |
| for (int i = 0; i < 4; i++) { | |
| ids[i] = i; | |
| printf("create thread %d\n", i); | |
| threads[i] = pthread_create(&threads[i], NULL, run, (void*)&ids[i]); | |
| } | |
| void* status; | |
| for (int i = 0; i < 4; i++) { | |
| printf("waiting for %d to join...\n", i); | |
| pthread_join(threads[i], &status); | |
| printf("thread %d joined with status %ld\n", i, (long)status); | |
| } | |
| pthread_exit(NULL); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment