lfqueue
lfqueue copied to clipboard
Tests: add more debugging, and a bugfix for dequeue
This doesn't fix everything: there's still a use-after-free bug in here somewhere, even with mfence
instead of lfence
or sfence
in case even stronger barriers made a difference at the locations you had them.
continue
goes to the end of the loop body, not the top. So if(we lose the race) continue;
attempts a CAS with uninitialized (or NULL) pn
. That's a bug.
The rest of this is some cleanups and improvements to the Makefile and tests.
By setting p->next
to (void*)-1
right before free()
ing, we can detect use-after free: we'll never see that pointer value normally (because it's not aligned, and other reasons), so if we ever read that from memory we know we shouldn't have read that memory, and it could have faulted.
I didn't commit all these changes perfectly the first time, so a couple later ones fix mistakes in earlier ones. But after the final one, it compiles with minimal warnings, and the tests run, only sometimes hitting the assertion failure. (Revealing a bug that already existed, but wasn't being detected before.)