Why does AQS not directly use one of the competing threads as the head node when creating a synchronization queue, but instead creates an empty object as the head node.Why did the author do this
enter image description here this is the codeenter image description here
2
The Java source for the AbstractQueuedSynchronizer explains it in the class comment:
The wait queue is a variant of a “CLH” (Craig, Landin, and Hagersten) lock queue.
[…]
CLH queues need a dummy header node to get started. But we don’t create them on construction, because it would be wasted effort if there is never contention. Instead, the node is constructed and head and tail pointers are set upon first contention.