STM: Potentially invalid assertion in STM.c
Summary
In the code for committing a transaction we have this sequence:
...
{
ACQ_ASSERT(tvar_is_locked(s, trec));
IF_STM_FG_LOCKS({
// We have locked the TVar therefore nonatomic addition is sufficient
NONATOMIC_ADD(&s->num_updates, 1);
});
unlock_tvar(cap, trec, s, e -> new_value, true);
}
ACQ_ASSERT(!tvar_is_locked(s, trec));
To me this seems like an potential bug. We assert a TVar is unlocked after we unlock it. But it's not obvious why the TVar couldn't have been locked by another thread in between the unlock operation and the assert.
I will leave the assert in for now as it might check some non-obvious undocumented invariant. But I will leave this here in case anyone else actually hits this assertion while nothing is wrong.