| 1 | #include <pthread.h> |
|---|
| 2 | #include <stdio.h> |
|---|
| 3 | #define NUM_THREADS 5 |
|---|
| 4 | int testex(void); |
|---|
| 5 | void *PrintHello(void *threadid) |
|---|
| 6 | { |
|---|
| 7 | long tid; |
|---|
| 8 | tid = (long)threadid; |
|---|
| 9 | printf("Hello World! It's me, thread #%ld!\n", tid); |
|---|
| 10 | pthread_exit(NULL); |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | int testex(void) |
|---|
| 14 | { |
|---|
| 15 | pthread_exit(NULL); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | int main (int argc, char *argv[]) |
|---|
| 19 | { |
|---|
| 20 | pthread_t threads[NUM_THREADS]; |
|---|
| 21 | int rc; |
|---|
| 22 | long t; |
|---|
| 23 | for(t=0; t<NUM_THREADS; t++){ |
|---|
| 24 | printf("In main: creating thread %ld\n", t); |
|---|
| 25 | rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); |
|---|
| 26 | if (rc){ |
|---|
| 27 | printf("ERROR; return code from pthread_create() is %d\n", rc); |
|---|
| 28 | exit(-1); |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | testex(); |
|---|
| 32 | } |
|---|
| 33 | |
|---|