Notes
[EMCpp]Item-40 Use std::atomic for Concurrency, volatile for Special Memory
· β 3 min read
std::atomic
is for data accessed from multiple threads without using mutexes (concurrent usage); volatile
is for memory where reads and writes should not be optimised away (special memory).
[EMCpp]Item-39 Consider Void Futures for One-Shot Event Communication
· β 3 min read
Using std::promise
s and futures is useful skill to create one-shot communication between a detecting task and reacting task.
[EMCpp]Item-38 Be Aware of Varying Thread Handle Destructor Behavior
· β 2 min read
Future destructors normally just destroy the future’s data members, execept for the final future referring to a shared state for a non-deferred task launched via std::async
, which blocks until the task completes.
[EMCpp]Item-37 Make std::threads Unjoinable on All Paths
· β 3 min read
Join-on-destruction can lead to difficult-to-debug performance anomalies; while detach-on-destruction can lead to difficult-to-debug undefined behavior.