On Thu, Mar 10, 2022 at 09:52:27PM +0100, Mark Kettenis wrote: Hello Mark,
> If you think about it, the invariants being tested by those KASSERTs should > not depend on whether the old or the new value is read if another CPU is > modifying that variable at the same time. Unless of course there is a > refcounting bug. But even with the barrier we're not guaranteed to catch > that bug. ... > > - KASSERT(atomic_load_int(&sc->task_refs.r_refs) == 0); > > + KASSERT(sc->task_refs.r_refs == 0); Unfortunately this transformation almost certainly isn't safe: for example, the non-atomic load can return values that were never written by any thread (e.g. due to load/store tearing amongst other fun effects). Laurie