Optimistic locking

We saw before that locks can sometimes be replaced with interlocked operations and we also used such operations to implement custom-made locking. Interlocked operations are also the basis for the optimistic locking pattern, which can be used to implement changes in shared data without using a classical locking mechanism.

Optimistic locking works when a chance of conflict between threads is very low. Like a database transaction mechanism, optimistic locking assumes that there will be no problem and applies required modifications on its own copy of the data (creates a new object, for example). In the second step, optimistic locking tries to commit the change. With one atomic step (usually implemented with an interlocked instruction), ...

Get Mastering Delphi Programming: A Complete Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.