CAS唤醒后继线程 为什么是从后向前遍历5金钱.anslist{background:url(sourc
技术问答
314 人阅读
|
0 人回复
|
2023-09-11
|
' J5 |! ], b/ m% c! `8 j- private void unparkSuccessor(Node node) {1 M9 N) y3 S% B! `% [
- /*
# j) t' k! r2 K# _ - * If status is negative (i.e., possibly needing signal) try5 ~3 Y6 v( Y& S* Z6 n, y* Z
- * to clear in anticipation of signalling. It is OK if this
$ N( @' {* c/ \" x. }9 ] - * fails or if status is changed by waiting thread.
Z% v3 v8 `. e/ v( A( e" r4 p - */5 ]" y3 T: ? J2 c& \
- int ws = node.waitStatus;
. U. ~4 j8 V, v* r. i - if (ws < 0)
. ^! ^: c8 H0 i6 w* B. `8 D - compareAndSetWaitStatus(node, ws, 0);
8 Z: X6 p K! G' W - 1 y" ^0 Z0 L/ L
- /*+ o# h: n" [0 c0 u/ P% u
- * Thread to unpark is held in successor, which is normally2 ^( A9 ~' I/ d4 N5 L5 @) r3 J
- * just the next node. But if cancelled or apparently null,) Z5 d& T8 i. \$ [
- * traverse backwards from tail to find the actual
1 D4 w8 H; t' B$ J A4 j" h7 w0 d - * non-cancelled successor.% R/ g: Z1 y, r7 [/ {
- *// j3 |2 c. [- F# X) X$ F5 D
- Node s = node.next;$ D7 F( y C$ o
- if (s == null || s.waitStatus > 0) {$ T! x6 S% Z4 \) A3 v
- s = null;
! W3 a- s3 ]1 ~ L% I - for (Node t = tail; t != null && t != node; t = t.prev)5 i- t, a1 f5 I) d- X. e5 x
- if (t.waitStatus <= 0)# N) D. k) m# a0 v# S4 }) _7 s
- s = t;6 X* b9 b" }1 x. |% p& Y7 b
- }
% F* e! L0 J( ~" S% V - if (s != null)
$ A* k) ] t1 _- S) V' Y, ]( v - LockSupport.unpark(s.thread); }
1 G# M: x! `: _, q5 H/ K 如果没有合法的数据,从后向前遍历,为什么这么做呢?从前向后不行吗?
2 i9 t5 T3 Y# ]& N/ a3 ?我知道答案 回答被采纳将会获得5 金钱 已有0人回答 |
|
|
|
|
|