ASSERT_EXCLUSIVE_ACCESS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 πŸ‘‘

  1. 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 ✨
  2. 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


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