My understanding was that as long as one access local objects only, one shouldn't need to hold *any* locks. But perhaps that's too good to be possible.
The problem is following pointers to global objects. When we read a pointer from a local object, we can first examine the local/global flag of the object it points to. If it's local, it's our own object and it can't change under our feet, so we can just go on. If it's global, we need to get the global lock, and then we can access the rest object.
Races we must consider is if the local flag is changing at the same time. It can't change from local to global, since in that case it is our object, so only we could change the flag and we're not doing it.
For changes from global to local, I think we're safe if we have the only reference to the object. I.e. the procedure could be: Get the global lock. Check that there is exactly one reference. Set the flag to local.
/ Niels Möller (vässar rödpennan)
Previous text:
2004-02-02 22:25: Subject: Re: Default backend and thread backends?
It's even safer than that since B has to hold the global write lock while it does that operation, so A doesn't do anything during that time (since it certainly wouldn't release its read lock in the time gap you show).
/ Martin Stjernholm, Roxen IS