MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / libc_ex7

Function libc_ex7

examples/libc/ex7.c:69–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67}
68
69int libc_ex7(void) {
70 unsigned long count;
71
72 setvbuf(stdout, NULL, _IONBF, 0);
73
74 /* initialize main event cond var */
75 pthread_cond_init(&main_event.cond, NULL);
76 pthread_mutex_init(&main_event.mutex, NULL);
77 main_event.flag = 0;
78
79 for (count = 0; count < 20; ++count) {
80 pthread_t thread;
81 int status;
82
83 /* pass down the milli-second timeout in the void* param */
84 status = pthread_create(&thread, NULL, test_thread, (void*) (count
85 * 100));
86 if (status != 0) {
87 printf("status = %d, count = %lu: %s\n", status, count, strerror(
88 errno));
89 return 1;
90 } else {
91
92 /* wait for the event posted by the child thread */
93 pthread_mutex_lock(&main_event.mutex);
94 while (main_event.flag == 0) {
95 pthread_cond_wait(&main_event.cond, &main_event.mutex);
96 }
97 main_event.flag = 0;
98 pthread_mutex_unlock(&main_event.mutex);
99
100 printf("count = %lu\n", count);
101 }
102
103 usleep(10);
104 }
105
106 return 0;
107}
108#include <finsh.h>
109FINSH_FUNCTION_EXPORT(libc_ex7, example 7 for libc);

Callers

nothing calls this directly

Calls 8

pthread_cond_initFunction · 0.85
pthread_mutex_initFunction · 0.85
pthread_createFunction · 0.85
pthread_mutex_lockFunction · 0.85
pthread_cond_waitFunction · 0.85
pthread_mutex_unlockFunction · 0.85
printfFunction · 0.50
usleepFunction · 0.50

Tested by

no test coverage detected