java.util.concurrent.locks 
static final class AbstractQueuedSynchronizer.Node
extends ObjectCopy the code

The node class for waiting queues

This wait queue is a variation of the “CLH” lock queue (three names: Craig, Landin, and Hagersten). CLH locks are commonly used for spin locks. Instead, we use them to block the synchronizer, but use the same basic strategy to keep some control information about the thread in its node predecessor. A “statue” field at each node records whether a thread should block. A node is signaled when its predecessor (waiting node) is released. Otherwise, each node in the queue acts as a monitor for a particular notification style, which also contains a waiting thread. Although this statue field does not control whether a thread is granted a lock. A thread will try to request it if it is the first one in the queue. But being first (the node entering the queue) does not guarantee success (the request). It only gives the right to compete. Therefore, the current free competitor thread may need to wait again.

To join the CLH lock, you can join nodes in an atomic fashion as the new tail of the queue (node). To exit the queue, you just set the header.