Function critical_section::acquire
source · pub unsafe fn acquire() -> u8Expand 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 token”u8that you must pass to the correspondingreleasecall, and treat opaquely otherwise.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 token that does not come from the correspondingacquirecall.