|
|
|
|
|
by Someone
4766 days ago
|
|
100% correct; before this standard, there was no standard for how C++ code should behave when run by multiple threads. Also, I do not think the claim that const member functions cannot have side effects is correct. For example, it is OK, but very bad practice to have a const member function update a global integer counter. |
|
* what the compiler will enforce: this has nothing to do with thread safety, and will allow what you mention.
* what guarantees the standard library will give:
[17.6.5.9/3] A C++ standard library function shall not directly or indirectly modify objects (1.10) accessible by threads other than the current thread unless the objects are accessed directly or indirectly via the function’s non-const arguments, including this.
This means that the standard library assumes that your const objects will be thread safe in order to guarantee thread-safety itself. Updating a global without synchronization is not thread-safe.