Is ReferenceCountedObjectPtr <> assignment atomic?


#1

Consider:

struct Obj : public ReferenceCountedObject {
  typedef ReferenceCountedObjectPtr <Obj> Ptr;
};

Obj::Ptr ptr = new Obj;

void thread1 ()
{
  ptr = new Obj;
}

Ptr  thread2 ()
{
  return ptr;
}

Is the assignment in thread1 atomic? By this, I mean will thread2 always either get the old Obj or the new Obj, with no leaks and no exceptions?


#2

Well, that’s the idea!