P99
#define P99_CRITICAL
Value:
P00_BLK_START                                                        \
P00_BLK_DECL_STATIC(atomic_flag, P99_LINEID(crit), ATOMIC_FLAG_INIT) \
P99_SPIN_EXCLUDE(P99_LINEID(crit))

Protect the following block or statement as a critical section of the program.

Internally this uses a static atomic_flag as a spinlock, so this is an active wait.

Warning:
Such a section should only contain a handful of statements.
Such a section should not contain preliminary exits such as goto, break, return, longjmp, or P99_UNWIND etc.
 P99_CRITICAL {
    // do some operations on a fragile resource here
 }

Such a critical section is only protected against threads that try to enter this same critical section. Threads may well simultaneously be in different critical sections.

Remarks:
Don't use this if you just want to protect e.g a counter that is shared between different threads. _Atomic and the operations on atomic variables are more appropriate for that.
See also:
P99_SPIN_EXCLUDE to protect several critical sections against each other.
P99_MUTUAL_EXCLUDE that is more suited for larger sections.
Warning:
Restrictions on preliminary exits from the dependent block or statement apply.
See also:
P99_PROTECTED_BLOCK
P99_GUARDED_BLOCK

Definition at line 1372 of file p99_atomic.h.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines