От: | landerhigh | ||
Дата: | 22.01.16 13:11 | ||
Оценка: |
class PseudoClass
{
std::shared_ptr<std::vector<Something>> m_DataMember;
public:
void SomeFunc()
{
//
//
m_DataMember = std::make_shared<std::shared_ptr<std::vector<Something>>>(getNewVectorOfSomething());
}
private:
void RunInThread()
{
std::shared_ptr<std::vector<Something>> localCopy = m_DataMember;
for (auto it = localCopy->begin(); it != localCopy->end(); ++it)
{
// This space is intentionally left empty
}
}
}
If multiple threads of execution access the same shared_ptr without synchronization and any of those accesses uses a non-const member function of shared_ptr then a data race will occur
void RunInThread()
{
for (auto it = m_DataMember->begin(); it != m_DataMember->end(); ++it)
{
// This space is intentionally left empty
}
}