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>
26 lines
1.1 KiB
Markdown
26 lines
1.1 KiB
Markdown
# 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 manual
|
|
`lock()`/`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::thread` is joined or detached before destruction; prefer `std::jthread`
|
|
(C++20).
|
|
- `std::async` futures: the returned future's destructor blocks; don't discard
|
|
it by accident.
|
|
- Atomics: `memory_order_relaxed` only 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.
|