Always declare std::mutex as mutable in C++11?

前端 未结 4 1280
甜味超标
甜味超标 2020-12-23 13:55

After watching Herb Sutter\'s talk You Don\'t Know const and mutable, I wonder whether I should always define a mutex as mutable? If yes, I guess the same holds for any sync

4条回答
  •  攒了一身酷
    2020-12-23 14:42

    The accepted answer covers the question, but it's worth mentioning that Sutter has since changed the slide that incorrectly suggested that const == mutable == thread-safe. The blog post that lead to that slide change can be found here:

    What Sutter got wrong about Const in C++11

    TL:DR Const and Mutable both imply Thread-safe, but have different meanings in regards to what can and can't be changed in your program.

提交回复
热议问题