Fix lock-free queue bugs, add GitHub Actions CI, and add ABA stress test#10
Fix lock-free queue bugs, add GitHub Actions CI, and add ABA stress test#10
Conversation
|
CI改成最新的github提供的workflow @copilot |
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
Updated in ad326ff — the workflow now follows GitHub's official C/C++ CI starter template ( |
|
設計一款更在multithread更容易發生ABBA的測試方法,來測試該LFQUEUE有無此弱點 @copilot |
Co-authored-by: darkautism <3898040+darkautism@users.noreply.github.com>
Added The test maximises ABA exposure compared to the existing tests by:
Each node carries a The queue passes the test (8 000 000 ops, no corruption detected), confirming the hazard pointer scheme correctly prevents ABA. |
Several correctness bugs in the hazard pointer implementation and test harness, plus missing CI since Travis CI is no longer free for OSS.
Bug Fixes
Wrong
callocelement sizes inlfq_init:HP(array of pointers) andtid_map(array ofint) were both allocated withsizeof(struct lfq_node)— 3× overallocation that masked out-of-bounds writes:Thread ID off-by-one in test consumer:
ATOMIC_ADD(&cn_t, 1)returns 1-based values (1…MAX_CONSUMER), causing the last consumer to writeHP[MAX_CONSUMER]— one past the end. Fixed:ATOMIC_ADD(&cn_t, 1) - 1.smb()/lmb()undefined on non-x86 platforms: Added#elsefallback tomb()so the code compiles on ARM/RISC-V.Memory leak in
lfq_initfailure path: If the secondcallocfailed,tmpnodewas leaked. Addedfree(tmpnode)before the early return.CI
.travis.ymlwith a GitHub Actions workflow (.github/workflows/ci.yml) using the official C/C++ CI starter template, runningmakeandmake testonubuntu-latestwithcontents: readpermissions.ABA Stress Test
Added
test_aba.c: a dedicated test designed to maximise the conditions under which the ABA problem would manifest in a CAS-based lock-free queue.The ABA problem: a CAS on a pointer succeeds spuriously when a node is dequeued, freed, and a new node is allocated at the same address before a stale CAS completes — causing the queue to operate on a logically different node without detecting the change.
How this test maximises ABA probability compared to the existing tests:
THREAD_YIELD()when queue emptyLIVE_MAGIC/DEAD_MAGICsentinel per nodeEach node carries a
LIVE_MAGICvalue on enqueue, poisoned toDEAD_MAGICbeforefree(). Any ABA-induced use-after-free or stale-pointer read surfaces immediately as a magic mismatch. The queue passes the test (8,000,000 ops across 16 threads, zero corruption), confirming the hazard pointer scheme correctly prevents ABA.The Makefile is updated to build
bin/test_abaand include it inmake test.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.