3 ms·
No, it’s just switching from a pessimistic locking approach to an optimistic one: https://en.wikipedia.org/wiki/Optimistic_concurrency_control https://en.wikipe
by alexhutcheson 6y ago
No, it’s just switching from a pessimistic locking approach to an optimistic one: https://en.wikipedia.org/wiki/Optimistic_concurrency_control https://en.wikipedia.org/wiki/Optimistic_concurrency_control
- kroolik 6y agoI 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.