Lock-free Flag Using Atomics
Implement a lock-free flag in C using C11 atomics. The flag supports set, clear, and test operations, ensuring atomicity.
Constraints
- Use atomic_flag or atomic_bool.
- set() => true.
- clear() => false.
- test() returns bool.
- No locks allowed.
1#include <stdatomic.h>2void flag_set();3void flag_clear();4bool flag_test();