Add a code review skill with reference files for memory safety, concurrency, correctness idioms, false positives, cppreference lookup, and report format. Move the coding conventions from AGENTS.md into the skill's project-style reference so reviews enforce them. Co-authored-by: Qwen 3.8 27B <qwen3.8_27b-q3_k_xl@lmstudio.local>
1.1 KiB
1.1 KiB
Concurrency
Docs: cppreference "Concurrency support library", std::memory_order,
std::atomic.
- Shared mutable data is protected by a mutex or is
std::atomic; otherwise it's a data race (UB). - Use
std::scoped_lock/std::lock_guard/std::unique_lock, never manuallock()/unlock(). - Multiple mutexes locked together with
std::scoped_lock(a, b)or in a consistent order. - No callbacks, I/O, or user code invoked while holding a lock.
- Condition variables wait with a predicate (spurious wakeups).
std::threadis joined or detached before destruction; preferstd::jthread(C++20).std::asyncfutures: the returned future's destructor blocks; don't discard it by accident.- Atomics:
memory_order_relaxedonly when no other memory depends on the value. - Lambdas passed to threads don't capture locals by reference that may die first.
- Static local init is thread-safe; other lazy init (double-checked locking)
needs atomics or
std::call_once. - Coroutines: references/pointer parameters may dangle after the first suspension.