AQS源码图解
2021-05-23 16:39:17 0 举报
AQS源码图解
作者其他创作
大纲/内容
true
fasle
shouldPark
tryAcquire
AbstractQueuedSynchronizer
Thread.currentThread().interrupt();
tail==null
new Node()并CAS head(初始化队列)
park
内部
cancelAcquire
pre == head
false
State==0
Return false
acquire
CAS state
AbstractOwnableSynchronizer
rerutn true;
selfInterrupt
pred.waitStatus=-1
无限循环(自旋)
Sync
CAS 加入队尾
state
acquireQueued
enq 内部无限循环(自旋)
head
enq & return node
return node
tail
将cancelled节点退出队列
当前线程持有锁
Set ExclusiveOwnerThread & return true
setHead;failed=false;
pred.waitStatus==-1(signal)
NonfairSync
Set ExclusiveOwnerThread
addWaiter
State++ & return true
interrupted= Thread.interrupted()
CAS tail(加入队尾)return tail
new Node(currentThread)
failed=true;interrupted=false;
Thread exclusiveOwnerThread
finally代码块failed==true
pred.waitStatus>0(cancelled)
NonfairSync.lock
return interrupted
收藏
0 条评论
下一页