Two editors read the same value and independently prepare replacements. Serializing only the final assignment prevents overlapping writes but still permits a stale editor to overwrite the newer result. The acceptance condition has to be checked together with the assignment.
This example keeps an integer revision beside an immutable string payload. A replacement supplies the revision it read. Under one lock, the cell compares that expectation, either rejects the update or assigns the value, and advances the revision.
Compare and replace in one critical section
The Python lock reference describes primitive locking. The application-level revision rule here is additional policy. Every read and update must use the same cell interface; a caller directly editing its private attributes would violate the example's assumptions.
The public snapshot is a tuple containing an integer and a string, so it does not expose a nested mutable payload.…