I have a class which contains a BYTE*
, a reference counter and a CRITICAL_SECTION
which protects both of them from concurrent access.
I wanna replace all that with a std::tr1::shared_ptr<BYTE>
. The MSDN says that:
Multiple threads can read and write different shared_ptr objects at the same time, even when the objects are copies that share ownership.
Everything sounds alright, until I find out that the CRITICAL_SECTION
from the class is used outside of it to "lock" it and alter its contents in a mutually exclusive fashion. Okay, it's breaks encapsulation, I wanna change that.
I know shared_ptr
guarantees that the memory will be freed, but does it guarantee mutual exclusion when you write to the memory?