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
Previous text:
2004-02-02 21:34: Subject: Re: Default backend and thread backends?
- Let each memory object have a flag to indicate whether it's thread local or global.
- When a reference is added from a global to thread local thing, the latter becomes global. This is transitive - at this point it'd be necessary to follow all references in the thread local thing and mark all that as global too.
Hmm. This is tricky. At first I thought the above was open to the following race, relating to the use of an object X which is initially local to thread A:
| Thread A Thread B | | Check global/local | flag of object X. | | Make X global. | | Get all locks needed for using X. | | Use object X. Use object X. | V time
But we can save the day by the quite natural requirement that it's only thread A that can turn its local objects into global objects.
/ Niels Möller (vässar rödpennan)