3 ms·
I think its not entirely optimistic locking, because the condition is based on checksum value, which is expensive to compute. I don't recall the article mentio
by kroolik 6y ago
I think its not entirely optimistic locking, because the condition is based on checksum value, which is expensive to compute.
I don't recall the article mentioning it, but if you don't compute the actual checksum under the lock then you either cache it (under the lock) and update only successful writes, or you risk a race condition between time of the check and action.
That is, optimistic locking assumes that if the condition is true I immediately get exclusive lock. But here, condition check is completely separate from the action. When the checksums are equal, but another thread manage to enter and leave the critical section before you, then that invalidates the condition. But you need to synchronously let other threads know they must recompute.