ReentrantLock锁机制
2022-02-21 01:04:45 5 举报
ReentrantLock.lock
作者其他创作
大纲/内容
获取到锁,执行业务逻辑
true
return true
false
pred != null
setExclusiveOwnerThread()
getState()
节点是有效头结点,并且重新获取锁成功
enq(node);
setHead()
ws == Node.SIGNAL
往尾部插入节点
ReentrantLock.lock()
返回
predecessor()
tryAcquire(1)
p == head && tryAcquire(arg)
Node pred = tail
进入死循环
current == getExclusiveOwnerThread()
compareAndSetState()
hasQueuedPredecessors()查看队列是否有节点
ws = pred.waitStatus
==0
!=0
shouldParkAfterFailedAcquire
addWaiter(Node.EXCLUSIVE)
收藏
0 条评论
下一页