Modern C++ (C++11/14/17/20) provides standardized multithreading primitives in the <thread>, <mutex>, and <future> headers.
Primitives
- std::thread: Starts a new execution thread. Remember to
join()ordetach(). - std::mutex: Mutual exclusion to prevent data races. Always use
std::lock_guardorstd::unique_lockfor RAII safety. - std::atomic: Lock-free thread-safe operations on primitives.
std::async
Spawns a task and returns a std::future. Provides a higher-level abstraction than threads.