...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdatomic.h> #include <threads.h> atomic_flag flag = ATOMIC_VAR_INIT(0); int func(void *data) { while (!flag) { /* ... */ } return 0; } int main(void) { int result; thrd_t tid; if (thrd_success != thrd_create(&tid, func, NULL)) { /* Handle error */ } /* ... */ /* Set flag when done */ while (!atomic_flag_test_and_set(&flag)) ; /* Continue attempts */ return 0; } |
Exceptions
CON37-C-EX1: Implementations such as POSIX that provide defined behavior when multithreaded programs use custom signal handlers are exempt from this rule [IEEE Std 1003.1-2013].
...