peku33 peku33 - 1 year ago 120
C++ Question

Why shared_timed_mutex is defined in c++14, but shared_mutex in c++17?

C++11 introduced

and its extended version -

However, in c++14 we have
, but its 'parent', the
is going to be added in c++17.

Is there any reasonable explanation for that?

If I'm not going to use 'timed' functionality of
, is it going to be worse (slower, consuming more resources) than proposed

Answer Source

Shared mutex originally had timing in it, and was called shared_mutex.

An implementor (msvc iirc) noted they could implement it "cheaper" without timing. In particular, SRWLOCK is an existing primitive on windows that is sufficient to implement shared mutex, but timed requires extra machinery. (Via @t.c.). (However, I believe it isn't just easier because already written, but also fundamentally more expensive, at least on x86/64 windows)

It was too late to add a new type to the standard, but not too late to rename it.

So it was renamed to shared_timed_mutex, and the untimed version added in next standard.

Here is at least one of the papers involved in the rename.

We propose to rename shared_mutex to shared_timed_mutex:

(a) for consistency with the other mutexes (fixing naming inconsistency);

(b) to leave room for a shared_mutex which can be more efficient on some platforms than shared_timed_mutex.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download