Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>in C++11, any const member function call on this object will invoke internal synchronization as well</p> </blockquote> <p>Why? That synchronisation doesn't just magically appear in the class, it's only there if someone adds it explicitly.</p> <blockquote> <p>so potentially, a single const function call on this object will cost 2 lock/unlock operations</p> </blockquote> <p>Only if someone has added an internal mutex to it <strong>and</strong> you also use an external one ... but why on earth would you do that?</p> <blockquote> <p>Note that the global mutex is still needed, because const doesn't seem to do anything for writers (except possibly slowing them down as well, if one of the non-const methods calls a const method).</p> </blockquote> <p>If the class has an internal mutex that's used to make the <code>const</code> members thread-safe then it could also be used for non-<code>const</code> members. If the class doesn't have an internal mutex, then the situation is identical to the C++98 one.</p> <p>I think you're seeing a problem that doesn't exist.</p> <p>Herb's "new meaning for const" is not enforced by the language or compiler, it's just design guidance, i.e. an idiom for good code. To follow that guidance you don't add mutexes to every class so <code>const</code> members are allowed to modify <code>mutable</code> members, <strong>you avoid mutable members!</strong> In the rare cases where you absolutely must have mutable members, either require users to do their own locking (and clearly document the class as requiring external synchronisation) or add internal synchronisation and pay the extra cost ... but those situations should be rare, so it's not true that "C++11 objects are slower because of the new const" because most well-designed objects don't have mutable members anyway.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload