mirror of
https://github.com/cpp-best-practices/cppbestpractices.git
synced 2025-12-17 11:14:35 +03:00
Merge pull request #26 from rob100/mm_rule
Suggestion: Adding M&M rule to Threadability
This commit is contained in:
@@ -8,4 +8,11 @@ Global data leads to unintended side effects between functions and can make code
|
|||||||
|
|
||||||
## Avoid Heap Operations
|
## Avoid Heap Operations
|
||||||
|
|
||||||
Much slower in threaded environments. In many or maybe even most cases, copying data is faster. Plus with move operations and such and things
|
Much slower in threaded environments. In many or maybe even most cases, copying data is faster. Plus with move operations and such and things.
|
||||||
|
|
||||||
|
## Mutex and mutable go together (M&M rule, C++11)
|
||||||
|
For member variables it is good practice to use mutex and mutable together. This applies in both ways:
|
||||||
|
* A mutable member variable is presumed to be a shared variable so it should be synchronized with a mutex (or made atomic)
|
||||||
|
* If a member variable is itself a mutex, it should be mutable. This is required to use it inside a const member function.
|
||||||
|
|
||||||
|
For more information see the following article from Herb Sutter: http://herbsutter.com/2013/05/24/gotw-6a-const-correctness-part-1-3/
|
||||||
Reference in New Issue
Block a user