Is it possible to use the ReferenceCountedObject in a multi-thread environment?
[i]if (Atomic::decrementAndReturn (refCounts) == 0) [/i]
and ReferenceCountedObject::incReferenceCount() does:
I’m wondering what happens if two threads get scheduled in the following way:
[THREAD A] [ReferenceCountedObject::decReferenceCount] Atomic::decrementAndReturn (refCounts) (returns "0") [THREAD B] [ReferenceCountedObject::incReferenceCount] Atomic::increment(refCounts) [THREAD A] [ReferenceCountedObject::decReferenceCount] comparison with "0" -> delete this instance [THREAD B] .... has a reference to a disposed object.... (?)
Am I missing something? Don’t we need a “full” mutex to avoid this situation?