How does livelock look in code? On the Internet, found only examples of life, where people meet in the corridor.

1 answer 1

An example would be a simple consensus algorithm. Suppose there is some algorithm that matches the current value of some register. If, at the time of consensus, a message is received to update the data, the algorithm is reset and starts over. If such messages arrive too often, that live lock turns out - the system constantly works, but cannot agree on the value. A simplified example (this is not a consensus algorithm) would be the counting of all records that the application manages - if at the time of counting a message arrives that a record has been changed or added, the algorithm should start over again. If messages are added too often, the system gets into the live lock.