pub unsafe fn acquire() -> RestoreStateExpand 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
acquirecall must be paired with exactly onereleasecall in the same thread. acquirereturns a “restore state” that you must pass to the correspondingreleasecall.acquire/releasepairs must be “properly nested”, ie it’s not OK to doa=acquire(); b=acquire(); release(a); release(b);.- It is UB to call
releaseif the critical section is not acquired in the current thread. - It is UB to call
releasewith a “restore state” that does not come from the correspondingacquirecall. - It must provide ordering guarantees at least equivalent to a
core::sync::atomic::Ordering::Acquireon a memory location shared by all critical sections, on which thereleasecall will do acore::sync::atomic::Ordering::Releaseoperation.