# 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.