Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 4
    A question though, if you are not modifying anything, why do u need to use a mutex in first place? I just want to understand this. Commented Aug 19, 2016 at 4:39
  • @Misgevolution you are modifying something, you just are controlling who/how can do the modification via const. A really naive example, imagine if I only give non-const handles to friends, enemies get a const handle. Friends can modify, enemies cannot.
    – iheanyi
    Commented May 22, 2017 at 21:35
  • 3
    Note: here's a great example of using the keyword mutable: stackoverflow.com/questions/15999123/… Commented Aug 5, 2017 at 17:19
  • I wish it could be used to override const (of types) so I don't have to do this: class A_mutable{}; using A = A_mutable const; mutable_t<A> a;, if I want const-by-default, i.e. mutable A a; (explicit mutable) and A a; (implicit const).
    – alfC
    Commented Oct 18, 2019 at 22:01
  • 6
    @Misgevolution because other threads are modifying.
    – Dexter
    Commented Feb 3, 2022 at 9:48