reeeeeelman on Nostr: Looking for thoughts on making a class thread-safe. I am currently using Atomic(s) ...
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 say it had a print because i am too god-damned lazy to write out one
nigger.print(nigger.vomit())
}
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 and 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.
✙ dcc :pedomustdie: :phear_slackware: (nprofile…3hg5) @p @@gentoobro@shitpost.cloud Zergling_man (nprofile…pltp)
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 say it had a print because i am too god-damned lazy to write out one
nigger.print(nigger.vomit())
}
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 and 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.
✙ dcc :pedomustdie: :phear_slackware: (nprofile…3hg5) @p @@gentoobro@shitpost.cloud Zergling_man (nprofile…pltp)