Function critical_section::acquire

source ·
pub unsafe fn acquire() -> RestoreState
Expand description

Acquire a critical section in the current thread.

This function is extremely low level. Strongly prefer using with instead.

Nesting critical sections is allowed. The inner critical sections are mostly no-ops since they’re already protected by the outer one.

Safety

  • Each acquire call must be paired with exactly one release call in the same thread.
  • acquire returns a “restore state” that you must pass to the corresponding release call.
  • acquire/release pairs must be “properly nested”, ie it’s not OK to do a=acquire(); b=acquire(); release(a); release(b);.
  • It is UB to call release if the critical section is not acquired in the current thread.
  • It is UB to call release with a “restore state” that does not come from the corresponding acquire call.
  • It must provide ordering guarantees at least equivalent to a core::sync::atomic::Ordering::Acquire on a memory location shared by all critical sections, on which the release call will do a core::sync::atomic::Ordering::Release operation.