KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a class that is accessed from multiple threads. Both of its getter and setter functions are guarded with locks. Are the locks for the getter functions really needed? If so, why? class foo { public: void setCount (int count) { boost::lock_guard<boost::mutex> lg(mutex_); count_ = count; } int count () { boost::lock_guard<boost::mutex> lg(mutex_); // mutex needed? return count_; } private: boost::mutex mutex_; int count_; };
Tags (comma-separated)
Save Edits
Cancel