isocpp / isocpp/CppCoreGuidelines
Make mutexes mutable to preserve function constness
Open
@cubbimew is already working on this.
Since Apr 10, 2017.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
Something I have recently seen is people removing const from read only functions due to adding a mutex to control access and of course mutex changes state when used.
Example:
// rvo will use the vector move constructor...
std::vector<widget> get() const
{
std::unique_lock<std::mutex> lk(cs_);
std::vector<widget> copy(widgets_);
return copy;
}
// in class definition
mutable std::mutex cs_;
std::vector<widget>widgets_;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.