What is Slipped Conditions?

Slipped conditions means, that from the time a thread has checked a certain condition until it acts upon it, the condition has been changed by another thread so that it is errornous for the first thread to act. Here is a simple example:

To avoid slipped conditions the testing and setting of the conditions must be done atomically by the thread doing it, meaning that no other thread can check the condition in between the testing and setting of the condition by the first thread.

A More Realistic Example

You may rightfully argue that you would never implement a Lock like the first implementation shown in this text, and thus claim slipped conditions to be a rather theoretical problem. But the first example was kept rather simple to better convey the notion of slipped conditions.

A more realistic example would be during the implementation of a fair lock, as discussed in the text onStarvation and Fairness. If we look at the naive implementation from the textNested Monitor Lockout, and try to remove the nested monitor lock problem it, it is easy to arrive at an implementation that suffers from slipped conditions. First I'll show the example from the nested monitor lockout text:

The missed signals problems is the reason that theFairLockimplementation shown in the textStarvation and Fairnesshas turned theQueueObjectclass into a semaphore with two methods:doWait()anddoNotify(). These methods store and react the signal internally in the QueueObject. That way the signal is not missed, even ifdoNotify()is called beforedoWait().

Next:

Locks in Java

Jakob Jenkov

results matching ""

    No results matching ""