Can we just put shared_mutex under the same header file, rather than a separate <shared_mutex> header file?
When I use shared_mutex
, I thought I only need to #include <mutex>
. It turns out that I need to #include <shared_mutex>
as well.
Is it more convenient to put all related mutexes into one header file <mutex>
?
Pointing out the premise of this question would be helpful to future academia.
If we take a closer look at the standard library, we see a certain pattern; a simple example is a look at the
memory
header which contains a few standard classes for easy dynamic memory management along with many functions and helper classes. This is also the case with thealgorithm
header.The OP asks:
When Howard Hinnant proposed Shared locking in C++, in his Proposed Wording, he writes it exactly like this:
From the very beginning, he meant it to be in a separate header and made it so. Somehow this got into the standard exactly like this.
Can we correct this [if we imply there is a mistake to begin with]? Theoretically yes. Practically, it is complicated. C++ has always promised to be a stable language. Stroustrup has always reiterated on this throughout his over 50 years of work on this language. Trying to change this subtle diversion in the standard library is unnecessary and arguably harmless. Some users of the standard library will even see this as an advantage rather than an inconvenience.
Edit: Howard has given a clarification on this subject. I will quote this verbatim: