Concurrency Anti-pattern Catalog for Java

Missing or nonexistent signals anti-pattern

Problem: This pattern generalizes the losing a notify bug pattern to all signals. The losing a notify bug is defined as occurring “If a notify() is executed before its corresponding wait(), the notify() has no effect and is “lost" ... the programmer implicitly assumes that the wait() operation will occur before any of the corresponding notify() operations" [FNU03]. Another example of this problem can occur at a barrier. If an await() from one thread never occurs then all of threads at the barrier may be stuck waiting.

Java example of the problem: ...

Context: Trying to coordinate threads based on assumptions regarding thread timing.

Solution: In the case of a notify signal, “One way of avoiding this bug pattern is to repeatedly execute the notify() operation until a condition stating that the notify() was received occurs" [FNU03]. Use concurrent mechanisms such as barriers and join() to prevent thread timing issues. Analogous solutions exist for other signals.

Java example of the solution: ...

References:

[FNU03] E. Farchi, Y. Nir, and S. Ur, “Concurrent bug patterns and how to test them," in Proc. of the 1st International Workshop on Parallel and Distributed Systems: Testing and Debugging (PADTAD 2003), Apr. 2003.