Concurrency support in C++17
C++17 brought with it one major advance and several minor tweaks to concurrency-related features. Let us quickly cover the latter first. The std::lock()
function that was introduced in C++11 now has a corresponding RAII object, std::scoped_lock
. A shared mutex, std::shared_mutex
, otherwise known as a read-write mutex, was added (again, matching the corresponding POSIX feature). This mutex allows multiple threads to proceed as long as they do not need exclusive access to the locked resource. Usually, such threads perform read-only operations, while a writer thread needs exclusive access, hence the name read-write lock. It's a clever idea in theory, but most implementations offer dismal performance.
Of note is a new feature that allows portably determining the cache line size for L1 cache, std::hardware_destructive_interference_size
, and std::hardware_constructive_interference_size
. These constants help create cache-optimal data structures that avoid...