annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 #include <pthread.h>
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2 #include <stdio.h>
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 #include <stdlib.h>
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4 #define NUM_THREADS 5
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6 void *PrintHello(void *threadid)
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 {
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 long tid;
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 tid = (long)threadid;
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10 printf("Hello World! It's me, thread #%ld!\n", tid);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 pthread_exit(NULL);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12 }
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
13
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
14 int main (int argc, char *argv[])
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
15 {
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
16 pthread_t threads[NUM_THREADS];
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17 int rc;
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18 long t;
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 for(t = 0; t < NUM_THREADS; t++)
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20 {
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 printf("In main: creating thread %ld\n", t);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 if (rc)
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24 {
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 printf("ERROR; return code from pthread_create() is %d\n", rc);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
26 exit(-1);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 }
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
28 }
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
29
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
30 /* Last thing that main() should do */
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
31 pthread_exit(NULL);
adcfad6e86fb Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 }