ASSERT_EXCLUSIVE_ACCESS(9)
π ASSERT_EXCLUSIVE_ACCESS π
ok so you found a page from the Kernel API Manual and it's lowkey about proving nobody else is touching your variable at the same time. bestie, this is a vibe check for concurrency π₯
β¨ NAME β¨
ASSERT_EXCLUSIVE_ACCESS β assert no concurrent accesses to @var
π SYNOPSIS π
ASSERT_EXCLUSIVE_ACCESS (var );
π¦ ARGUMENTS π¦
varβ the variable you're asserting on, i.e. the main character of this whole situation π
πΈ DESCRIPTION πΈ
Okay so picture this: you're asserting that there are no concurrent accesses to var β no readers and no writers, not a single one, nobody, periodt π
This assertion is literally made for specifying properties of concurrent code where a violation cannot be detected as a normal data race. It's giving "the data race detector can't catch this so I'm doing it myself" energy.
Like, imagine you've figured out that no other users of an object are left, so exclusive access is expected β but the object isn't actually freed. This assertion lets you check that the property actually holds. Here's how that looks:
if (refcount_dec_and_test(obj->refcnt)) {
ASSERT_EXCLUSIVE_ACCESS(*obj);
do_some_cleanup(obj);
release_for_reuse(obj);
}
See? Iconic. The refcount_dec_and_test(obj->refcnt) hits, and then you assert nobody else is in there before you do your cleanup and release π«Ά
π NOTE π
ASSERT_EXCLUSIVE_ACCESS_SCOPED, if applicable, performs more thorough checking if there's a clear scope where no concurrent accesses are expected to exist. so if that applies to you, she's the better fit β¨- For cases where the object is freed,
KASAN <kasan.html>_ is a better fit for detecting use-after-free bugs. different tool, different job, no cap π
π SEE ALSO π
Kernel file ./include/linux/kcsan-checks.h
__kcsan_check_access(9)__kcsan_mb(9)__kcsan_wmb(9)__kcsan_rmb(9)__kcsan_release(9)kcsan_disable_current(9)kcsan_enable_current(9)kcsan_nestable_atomic_begin(9)kcsan_nestable_atomic_end(9)kcsan_flat_atomic_begin(9)kcsan_flat_atomic_end(9)kcsan_atomic_next(9)kcsan_set_access_mask(9)kcsan_begin_scoped_access(9)kcsan_end_scoped_access(9)__kcsan_check_read(9)__kcsan_check_write(9)__kcsan_check_read_write(9)kcsan_check_read(9)kcsan_check_write(9)kcsan_check_read_write(9)ASSERT_EXCLUSIVE_WRITER(9)ASSERT_EXCLUSIVE_WRITER_SCOPED(9)ASSERT_EXCLUSIVE_ACCESS_SCOPED(9)ASSERT_EXCLUSIVE_BITS(9)
aaaand that's the page!! π this one lives in ./include/linux, dated October 2026, and it goes by ASSERT_EXCLUSIVE_ACCESS(9) if you ever need to find her again. mwah, go assert those exclusive accesses responsibly bestie ππ§
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms