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 onerelease
call in the same thread. acquire
returns a “restore state” that you must pass to the correspondingrelease
call.acquire
/release
pairs must be “properly nested”, ie it’s not OK to doa=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 correspondingacquire
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 therelease
call will do acore::sync::atomic::Ordering::Release
operation.