-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_world.c
35 lines (23 loc) · 832 Bytes
/
hello_world.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
int thread_count;
void *Hello(void* rank){
long my_rank = (long) rank;
printf("Hello from thread %1ld of %d\n", my_rank, thread_count);
return NULL;
}
int main(int argc, char* argv[]) {
long thread;
pthread_t* thread_handles;
thread_count = strtol(argv[1], NULL, 10);
thread_handles = malloc (thread_count*sizeof(pthread_t));
for (thread = 0; thread < thread_count; thread++)
pthread_create(&thread_handles[thread], NULL, Hello, (void*) thread);
printf("Hello from the main thread\n");
printf("%d", strcmp("Member", "Member"));
for (thread = 0; thread < thread_count; thread++)
pthread_join(thread_handles[thread], NULL);
free(thread_handles);
return 0;
} /* simple concurrent program */