In the example given in http://en.cppreference.com/w/cpp/thread/shared_mutex
A std::shared_lock<std::shared_mutex>
is used in the get()
method so
Multiple threads/readers can read the counter's value at the same time.
I wonder why the lock is even necessary for reading threads here? Is it for the consideration of variable's across thread visibility, so the reading thread is ensured to read up-to-date value of the variable (not the local copy in the cache of the CPU core where the thread is running in, which could be outdated) ?