Hi

The problem code is here (line 00120-00150):
http://www.cryptopp.com/docs/ref/misc_8h-source.html

simple_ptr is not a POD, so when multiple threads calling its
initialization at the same time, some may get not yet constructed
object or the construction may occur multimple times.

If two threads enter method at the same time, and the construction of
s_pObject is started in both (as static variable flag is not
threadsafe).
For one thread it is finished, and s_pObject.m_p = m_objectFactory();
is
executed. Then it is finished for second thread and m_p  is back NULL.

Another problem is that once a thread enters retry loop it may never
leave it. As s_objectState is not marked as volatile, the compiler
(MSVC8, Release) optimises out reads of this variable.

Why actually to initialize "without using locks" ? If the goal is
performance, then double-checked locking should be choosen.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
-~----------~----~----~----~------~----~------~--~---

Reply via email to