I have a question about boost :: shared_ptr.
There are lots of thread.
class CResource
{
xxxxxx
}
class CResourceBase
{
public:
void SetResource(shared_ptr<CResource> res)
{
m_Res = res;
}
shared_ptr<CResource> GetResource()
{
return m_Res;
}
private:
shared_ptr<CResource> m_Res;
}
CResourceBase base;
//----------------------------------------------
Thread A:
while (true)
{
......
shared_ptr<CResource> nowResource = base.GetResource();
nowResource.doSomeThing();
...
}
Thread B:
shared_ptr<CResource> nowResource;
base.SetResource(nowResource);
...
//-----------------------------------------------------------
If thread A do not care the nowResource is the newest . Will this part of code have problem? I mean when ThreadB do not SetResource completely, Thread A get a wrong smart point by GetResource?
Another question : what does thread-safe mean? If I do not care about whether the resource is newest, will the shared_ptr nowResource crash the program when the nowResource is released or will the problem destroy the shared_point?