Looking for thoughts on making a class thread-safe. I am currently using Atomic(s) where possible and mutex locks otherwise, but this is fairly heavy and frankly it feels like I could do it better.
Just as an example:
class A { something vomit() { std::shared_lock<std::shared_mutex> lock(mutex_); return Blah; }; something Blah; mutable std::shared_mutex mutex_; } main: int main() { A nigger = A(); //let's just assume `something` takes a value because I am too god-damned lazy to write it out here. nigger.vomit("aaaaaaaa") }While this is correct (at least to the best of my understanding) my specific case has quite a few of these accessors, and to prevent issues I load them all into memory. This of course places quite the burden on the memory and also means every time I access anything it checks. So there can be 10, 20, etc people all looking at different variables at once. Again, supposedly correct but I feel like it can be done better (or can it?).
Let me know if you have any thoughts on the matter.