下面的代码:这个函数(操作符重载)线程安全吗?
ElementType& operator[] (int key)
{
//something like boost::mutex::scoped_lock
MutexLockType lock();
if(key < 0 || key > m_bound)
throw std::range_error("access out of bound");
return m_elements[key];
}
不,它不是 - 你怎么知道,当你的锁被释放时,元素不会被删除? – Erik 2011-03-13 13:40:57