P99

◆ P99_CRITICAL

#define P99_CRITICAL   P00_CRITICAL(P99_UNIQ(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.
// 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 1422 of file p99_atomic.h.