Mutex for simple data types
问题 I'm pretty new to concurrency, and I'm having trouble deciding on how to use mutexes. At the moment they are sprinkled all over my code where two threads interact. Would this use of mutexes be appropriate? class Foo { public: void SetMember(int n) { AcquireMutex(..); n_ = n; ReleaseMutex(...);} private: Thread() { while(1) { AcquireMutex(..); // Do something with n_ ReleaseMutex(...); } } }; I have quite a few data members that can be read and set from the outside by a different thread, and I