【发布时间】:2016-01-11 21:20:05
【问题描述】:
class C {
mutable std::mutex _lock;
map<string,string> deep_member;
public:
auto get_big_lump()
{
std::unique_lock<std::mutex> lock(_lock); // establish scope guard
return deep_member; // copy the stuff while it can't be changed on another thread.
}
};
关于保护和复制返回值的保证时间是什么? 是否会在持有锁时进行复制,或者在允许(或实际!)优化的情况下,是否可以在函数体返回后完成其中的一些?
【问题讨论】: