boost::uuids::random_generator and uniqueness with multiple threads

 ̄綄美尐妖づ 提交于 2019-12-03 12:59:18
Cubbi

This is a common error when using RAII locks: you forgot to give your lock a name in the line

      boost::mutex::scoped_lock(m_mRandomGen);

so it didn't lock anything at all. Change it to

      boost::mutex::scoped_lock lk(m_mRandonGen); // note the typo in mutex name

EDIT: what really happened: There was no compiler error despite the typo in the mutex name because the declaration

type(name);

is the same as

type name;

if the name has not been declared before. In other words, you've default-constructed a new scoped_lock called m_mRandomGen, not associated with a mutex.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!