Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualMatt-D

Posted 23 June 2013 - 01:05 PM

Note that in C++11 you'd likely need to protect mutable members with synchronization (e.g., in case your code ever runs in a multithreaded context), see:
GotW #6a: http://herbsutter.com/2013/05/24/gotw-6a-const-correctness-part-1-3/
GotW #6b: http://herbsutter.com/2013/05/28/gotw-6b-solution-const-correctness-part-2/

In particular:

 

In general, remember:

Guideline: Remember the “M&M rule”: For a member variable, mutable and mutex (or atomic) go together.

This applies in both directions, to wit:

(1) For a member variable, mutable implies mutex (or equivalent): A mutable member variable is presumed to be a mutable shared variable and so must be synchronized internally—protected with a mutex, made atomic, or similar.

(2) For a member variable, mutex (or similar synchronization type) implies mutable: A member variable that is itself of a synchronization type, such as a mutex or a condition variable, naturally wants to be mutable, because you will want to use it in a non-const way (e.g., take a std::lock_guard<mutex>) inside concurrent const member functions.

 

 

More details:

http://isocpp.org/blog/2012/12/you-dont-know-const-and-mutable-herb-sutter
http://musingstudio.com/2013/05/28/herb-sutter-gotw6-const-and-mutable/

20130110-130953.jpg
http://musingstudio.com/2013/01/10/herb-sutter-video-you-think-you-know-const-and-mutable/
 


#1Matt-D

Posted 23 June 2013 - 01:05 PM

Note that in C++11 you'd likely need to protect mutable members with synchronization, see:
GotW #6a: http://herbsutter.com/2013/05/24/gotw-6a-const-correctness-part-1-3/
GotW #6b: http://herbsutter.com/2013/05/28/gotw-6b-solution-const-correctness-part-2/

In particular:

 

In general, remember:

Guideline: Remember the “M&M rule”: For a member variable, mutable and mutex (or atomic) go together.

This applies in both directions, to wit:

(1) For a member variable, mutable implies mutex (or equivalent): A mutable member variable is presumed to be a mutable shared variable and so must be synchronized internally—protected with a mutex, made atomic, or similar.

(2) For a member variable, mutex (or similar synchronization type) implies mutable: A member variable that is itself of a synchronization type, such as a mutex or a condition variable, naturally wants to be mutable, because you will want to use it in a non-const way (e.g., take a std::lock_guard<mutex>) inside concurrent const member functions.

 

 

More details:

http://isocpp.org/blog/2012/12/you-dont-know-const-and-mutable-herb-sutter
http://musingstudio.com/2013/05/28/herb-sutter-gotw6-const-and-mutable/

20130110-130953.jpg
http://musingstudio.com/2013/01/10/herb-sutter-video-you-think-you-know-const-and-mutable/
 


PARTNERS