我们知道
std::deque::front()
返回deque的第一个元素的引用。
我想知道这段代码是否总是安全的://deque of lambdas
deque<function<void(void)>> funs;
// then is some other place:
// take a lock
m.lock();
auto f = move(funs.front()); // move the first lambda in f
funs.pop_front(); // remove the element from deque //now the value is hold by f
m_.unlock(); // unlock the resorce
f(); //execute f
我已经使用gcc-4.9尝试了这段代码,它可以正常工作,但我不知道我们是否可以认为这段代码是安全的!
m
上使用了lock()
,而在m_
上使用了unlock()
。 - Notinlist