I'm not 100% certain whether I like this. Consider the following concurrent pseudo-code:
class A {
public:
void add () {
// <locking happens here>
_v += "foo";
}
std::string const get () {
// <locking again>
return _v;
}
private:
std::string _v;
};
Now, if I launch multiple threads that call get () and add () at the same time, normally this would be thread-safe, if locking occurs. However, if I understood it correctly, get () can also return by reference, since it is const.Wouldn't this create race conditions?