Name Description Size
ConditionVariable.h 4603
CpuCount.h Return the number of cores on the system. If the system provides logical cores (such as hyperthreads) then count each logical core as an actual core. 533
ExclusiveData.h [SMDOC] ExclusiveData API A mutual exclusion lock class. `ExclusiveData` provides an RAII guard to automatically lock and unlock when accessing the protected inner value. Unlike the STL's `std::mutex`, the protected value is internal to this class. This is a huge win: one no longer has to rely on documentation to explain the relationship between a lock and its protected data, and the type system can enforce[0] it. For example, suppose we have a counter class: class Counter { int32_t i; public: void inc(int32_t n) { i += n; } }; If we share a counter across threads with `std::mutex`, we rely solely on comments to document the relationship between the lock and its data, like this: class SharedCounter { // Remember to acquire `counter_lock` when accessing `counter`, // pretty please! Counter counter; std::mutex counter_lock; public: void inc(size_t n) { // Whoops, forgot to acquire the lock! Off to the races!; } }; In contrast, `ExclusiveData` wraps the protected value, enabling the type system to enforce that we acquire the lock before accessing the value: class SharedCounter { ExclusiveData<Counter> counter; public: void inc(size_t n) { auto guard = counter.lock(); guard->inc(n); } }; The API design is based on Rust's `std::sync::Mutex<T>` type. [0]: Of course, we don't have a borrow checker in C++, so the type system cannot guarantee that you don't stash references received from `ExclusiveData<T>::Guard` somewhere such that the reference outlives the guard's lifetime and therefore becomes invalid. To help avoid this last foot-gun, prefer using the guard directly! Do not store raw references to the protected value in other structures! 12020
LockGuard.h 1106
Mutex.cpp static 2120
Mutex.h 2553
ProtectedData.cpp static 2662
ProtectedData.h 10640
Thread.cpp 869
Thread.h 8711
ThreadId.h 1060