0
thread safe and const member function
Hi I read somewhere that const member functions are always thread safe as it is read only operation on member variables. But what if other function is modifying the data which we are reading?
5 odpowiedzi
+ 1
Ketan Lalcheta the const memeber functions are nothing but the constant values which cannot be changed after defining it. So if you don't want the variable values to get changed you can use const memeber function for achieving it as any other functions can't change the values of it.
0
atomic?
volatile have conflicting pros and cons...
https://stackoverflow.com/questions/4557979/when-to-use-volatile-with-multi-threading
Feeding changing data to threads is tricky and error prone...
0
Hi Bob_Li, Atomic is very low level and need more care. I would go with mutex then but point is that const member function is not automatically thread safe and need some mechanism be it atomic or mutex. Right?
0
HI Aysha
Could not agree more...!
Const member function can have access of any member variables. It just a guarantee to compiler that this const function will not modify anything.
0
but fo you have guarantee that the value is up to date?