| 67 | } |
| 68 | |
| 69 | int 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> |
| 109 | FINSH_FUNCTION_EXPORT(libc_ex7, example 7 for libc); |
nothing calls this directly
no test coverage detected