ReentrantLock核心源码流程
2023-03-18 21:48:02
登录查看完整内容
举报
猜你喜欢
大纲/内容
thread=nullwaitStatus=-1
关键代码:acquireQueuedfinal Node p = node.predecessor(); if (p == head && tryAcquire(arg)) { setHead(node); p.next = null; // help GC failed = false; return interrupted; }
thread=线程2waitStatus=-1
入队、阻塞
可重入锁判断依据
state=0
next
阻塞线程2
线程2
thread=线程2waitStatus=0
excludeOwnerThread=线程2
pre
阻塞前的准备
线程1
state=1
excludeOwnerThread=null
释放锁
线程3
以下为锁被占用后,其他线程的入队列流程
thread=线程3waitStatus=0
excludeOwnerThread=线程1
出队准备工作
cas尝试加锁,成功
cas加锁,失败
thread=nullwaitStatus=0
LockSupport.park(this);
加锁依据
以下为锁释放后,重新竞争的流程
阻塞线程3
cas加锁,成功
0 条评论
回复 删除
下一页
职业:本科
作者其他创作:
BlockingQueue阻塞队列
154 2023-03-21
ReentrantLock核心源码流程
118 2023-03-18
自旋锁与非自旋锁
112 2023-03-06