]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/ex/pthread_join/main.c
update
[l4.git] / l4 / pkg / plr / ex / pthread_join / main.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <assert.h>
4
5 #include <pthread.h>
6 #include <pthread-l4.h>
7
8 #include <l4/re/env.h>
9 #include <l4/sys/kdebug.h>
10
11 static
12 void *thread(void *data)
13 {
14         (void)data;
15         for (unsigned i = 0; i < 2; ++i) {
16         //while (1) {
17                 printf("\033[31mhello world from thread\033[0m\n");
18                 sleep(1);
19         }
20         return NULL;
21 }
22
23 int main(int argc, char **argv)
24 {
25         (void)argc; (void)argv;
26
27         pthread_t pt;
28         int res;
29
30         printf("\033[32mhello from main thread\033[0m\n");
31
32         for (unsigned i = 0; i < 5; ++i) {
33                 printf("\033[32mLaunching worker thread.\033[0m\n");
34                 res = pthread_create(&pt, NULL, thread, NULL);
35                 assert(res == 0);
36                 res = pthread_join(pt, NULL);
37                 printf("\033[32mWorker thread returned.\033[0m\n");
38                 assert(res == 0);
39         }
40
41         return 0;
42 }