When I generate the random number with single thread, no duplicate in 4M uuids generated but if I generate with two threads each 1M, I see roughly 16-20 duplicates. What could
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.