Created
April 30, 2015 21:00
-
-
Save depp/3f04508a88a114734195 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
Notice how each number appears only once. | |
The order is still scrambled, but we don't care about the order. | |
Arg = 1 | |
Arg = 4 | |
Arg = 2 | |
Arg = 6 | |
Arg = 3 | |
Arg = 7 | |
Arg = 0 | |
Arg = 5 | |
Arg = 8 | |
Arg = 9 |
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 <stdint.h> | |
#include <stdio.h> | |
#define N 10 | |
void *thread_func(void *arg) | |
{ | |
int val = (int) (intptr_t) arg; | |
printf("Arg = %d\n", val); | |
return NULL; | |
} | |
int main() | |
{ | |
int i; | |
pthread_t threads[N]; | |
for (i = 0; i < N; i++) { | |
pthread_create(&threads[i], NULL, thread_func, | |
(void *) (intptr_t) i); | |
} | |
for (i = 0; i < N; i++) { | |
pthread_join(threads[i], NULL); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment