Is there best practice for managing Object shared by 2 or more others Object. Even when running on different thread?
For example A is created and a pointer to it is given to B and C. ObjA A = new ObjA(); B->GiveObj(A); C->GiveObj(A);
Now how can I delete objA?
So far what I though about is A monitor how many ref there are to it and when this counter is 0 it delete this (such as when A is passed, the receiver call A->Aquire(), when its done it call A->release();
Or I could tell B->RemoveObj(A); and C->RemoveObj(A); The problem with that is if B or C are running on a different thread, I cannot delete A until they are done with A, and they have seen The RemoveObj call. (Which require a bunch of messy flags).
Would there be a nice way to do this, possibly with Signal/Slot?
Thanks