...
| Code Block |
|---|
#include <threads.h>
#include <stdbool.h>
extern bool until_finish(void);
extern mtx_t lock;
extern cnd_t condition;
void func(void) {
if (thrd_success != mtx_lock(&lock)) {
/* Handle error */
}
while (until_finish()) { /* Predicate does not hold */
if (thrd_success != cnd_wait(&condition, &lock)) {
/* Handle error */
}
}
/* Resume when condition holds */
if (thrd_success != mtx_unlock(&lock)) {
/* Handle error */
}
} |
...