meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
programming:c:atomic [2021/01/17 18:16] – created niziakprogramming:c:atomic [2025/02/03 08:42] (current) niziak
Line 1: Line 1:
 +====== stdatomic.h ======
 +
 +[[https://stackoverflow.com/questions/39329311/difference-between-standards-atomic-bool-and-atomic-flag|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.
 +
 +[[https://en.cppreference.com/w/c/atomic/atomic_flag|atomic_flag]]
 +
 +
 +<code c>
 +#include <stdatomic.h>
 +
 +atomic_flag busy;
 +
 +if (atomic_flag_test_and_set(&busy) {
 +    return APP_ERR_BUSY;
 +}
 +...
 +atomic_flag_clear(&busy);
 +</code>
 +
 +===== 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 =====
 +
 +
 [[https://en.cppreference.com/w/c/atomic|Atomic operations library]] [[https://en.cppreference.com/w/c/atomic|Atomic operations library]]
 [[https://docs.oracle.com/cd/E77782_01/html/E77803/stdatomic.h-3a.html|stdatomic.h (3A) ]] [[https://docs.oracle.com/cd/E77782_01/html/E77803/stdatomic.h-3a.html|stdatomic.h (3A) ]]
  
 [[https://wiki.sei.cmu.edu/confluence/display/c/CON40-C.+Do+not+refer+to+an+atomic+variable+twice+in+an+expression]] [[https://wiki.sei.cmu.edu/confluence/display/c/CON40-C.+Do+not+refer+to+an+atomic+variable+twice+in+an+expression]]