[ZODB-Dev] Locking
Izak Burger
izak at upfrontsystems.co.za
Fri Jul 4 04:08:43 EDT 2008
Joseph Turian wrote:
> See if key is present in root.
> [it's not]
> Lock key write-access, so that no other client will try to write key.
> Compute value for key.
> Write value for key.
> Unlock key.
Just as an aside, theoretically speaking, checking for the existence of
the key should be included in the critical section (the area protected
by the lock), otherwise you create a race condition.
Example: process/thread A checks for a key and doesn't find it, A is
preempted and process/thread B is scheduled, B checks for the same key
and sees that it doesn't exist. B enters the critical section and
creates the key. Next, A is scheduled by the OS and enters the critical
section and tries to create the same key. Not good.
But as was already explained, all you need to do is check for a conflict.
Cheers,
Izak
More information about the ZODB-Dev
mailing list