Table of Contents

stdatomic.h

difference between standard's atomic bool and atomic flag

atomic_flag

atomic_flag is an atomic boolean type variable that is guaranteed to be lock-free.
It is used to provide synchronization within threads in programs. Unlike atomic_bool,
atomic_flag does not provide load or store operations.

atomic_flag

#include <stdatomic.h>
 
atomic_flag busy;
 
if (atomic_flag_test_and_set(&busy) {
    return APP_ERR_BUSY;
}
...
atomic_flag_clear(&busy);

atomic vars

Atomic variables are not guaranteed to be lock-free. It depends on implementation, e.g: Atomic access can be provided by spin locks.

others

Atomic operations library stdatomic.h (3A)

https://wiki.sei.cmu.edu/confluence/display/c/CON40-C.+Do+not+refer+to+an+atomic+variable+twice+in+an+expression