Mercurial
comparison playground/main.c @ 1:adcfad6e86fb
Updated naming and separated out some logic within seobeo.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Sep 2025 09:11:20 -0700 |
| parents | |
| children | d97ec3ded2ae |
comparison
equal
deleted
inserted
replaced
| 0:5695ef413be0 | 1:adcfad6e86fb |
|---|---|
| 1 #include <pthread.h> | |
| 2 #include <stdio.h> | |
| 3 #include <stdlib.h> | |
| 4 #define NUM_THREADS 5 | |
| 5 | |
| 6 void *PrintHello(void *threadid) | |
| 7 { | |
| 8 long tid; | |
| 9 tid = (long)threadid; | |
| 10 printf("Hello World! It's me, thread #%ld!\n", tid); | |
| 11 pthread_exit(NULL); | |
| 12 } | |
| 13 | |
| 14 int main (int argc, char *argv[]) | |
| 15 { | |
| 16 pthread_t threads[NUM_THREADS]; | |
| 17 int rc; | |
| 18 long t; | |
| 19 for(t = 0; t < NUM_THREADS; t++) | |
| 20 { | |
| 21 printf("In main: creating thread %ld\n", t); | |
| 22 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); | |
| 23 if (rc) | |
| 24 { | |
| 25 printf("ERROR; return code from pthread_create() is %d\n", rc); | |
| 26 exit(-1); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 /* Last thing that main() should do */ | |
| 31 pthread_exit(NULL); | |
| 32 } |