当前位置:网站首页>Detailed explanation of abstractqueuedsynchronizer, the cornerstone of thread synchronization

Detailed explanation of abstractqueuedsynchronizer, the cornerstone of thread synchronization

2022-06-24 12:50:00 jerry_ dyy

summary :

AQS Defines a synchronizer framework for multiple threads to access shared resources , adopt CLH Queue to achieve thread synchronization of a framework :

  In combination with the CLH queue , When multiple threads access the same resource :state when , Each thread will create a corresponding node and put it in the queue . Threads 1 The first to enter ,head It points to the thread 1 Node created 1, Then the node 1 You have access to resources , And the nodes created by the incoming thread are put into CLH Queue tail , All threads enter the waiting state . When head Threads in nodes 1 After accessing the resource , Threads 1 Wake up the following thread 2, Threads 2 take head Point to thread 2 The node 2, Now the node 1 Just out of the queue , Threads 2 At this point, you have access to the resource , And so on .

among state It is a resource that multiple threads must compete for ,state yes AbstarctQueuedSynchronizer A quilt in volatile The type of modification is int Member variables of , About state The operation of , That is, the operation of resources , It's all in tryXx

原网站

版权声明
本文为[jerry_ dyy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241048017869.html