CAS唤醒后继线程 为什么是从后向前遍历5金钱.anslist{background:url(sourc
技术问答
476 人阅读
|
0 人回复
|
2023-09-11
|
8 N% w" M% t# `/ a2 I1 d# p
- private void unparkSuccessor(Node node) {
/ H8 ~" ^% `) \1 D1 A& Z. n - /*
+ r* s3 g h( u9 X - * If status is negative (i.e., possibly needing signal) try' p) R. x) p0 d
- * to clear in anticipation of signalling. It is OK if this) e! x; g" x2 T4 G; ^- [5 r
- * fails or if status is changed by waiting thread.
3 Q0 W0 |! }% y! l - */" Q/ h- i* ]% k/ b
- int ws = node.waitStatus;
& L4 M. \; k6 B - if (ws < 0)! K0 z3 K8 r) e+ a3 {5 D6 j
- compareAndSetWaitStatus(node, ws, 0);* e! q# O7 Q# |6 H, U
- q: P7 g2 p% u2 F3 j/ U
- /*. f, K k. E9 i9 W
- * Thread to unpark is held in successor, which is normally
4 c( o6 P# V$ a3 @* A1 ] - * just the next node. But if cancelled or apparently null,& H" g; b' D0 ]) N- r
- * traverse backwards from tail to find the actual
7 F+ d; J# J0 `( \# W - * non-cancelled successor.
6 O6 q P) W. l" V - */
/ v. b% T$ o0 e- E) H - Node s = node.next;3 \, B$ Z, O) A' {& y# b; X k
- if (s == null || s.waitStatus > 0) {
" O1 I& J* K2 n9 k, J; y - s = null;
& _6 b) a, \% m; w3 }5 w - for (Node t = tail; t != null && t != node; t = t.prev)
0 M, S# ^6 E* U, G# }- J - if (t.waitStatus <= 0)" u) H% h6 {+ p/ G4 r7 w( B) G: T
- s = t;7 _! j: x3 ?" W; C
- }+ p/ |& O- {4 q( u$ w
- if (s != null); r2 |) H4 P6 i' z7 A. j
- LockSupport.unpark(s.thread); }( u- E8 e9 O2 {" j
如果没有合法的数据,从后向前遍历,为什么这么做呢?从前向后不行吗?$ h3 m, @& Y7 d- l2 u* q' |% h
我知道答案 回答被采纳将会获得5 金钱 已有0人回答 |
|
|
|
|
|