|
- L+ G0 [9 U" ?- o1 I- private void unparkSuccessor(Node node) {
/ R. f* W8 l1 O+ C/ o* I8 } - /*, I' \5 |: x; W+ ~. g0 H
- * If status is negative (i.e., possibly needing signal) try
( {$ O9 `0 i" M+ i0 }3 J( a' C - * to clear in anticipation of signalling. It is OK if this8 @' _/ V; j1 l6 ]/ ?* H+ l$ w9 Q) E
- * fails or if status is changed by waiting thread.
5 b! {, ^$ l0 w2 c' Q5 g - */3 v" f2 J2 A8 D8 x5 t1 B
- int ws = node.waitStatus;7 C4 x4 }2 R, C, o. V, x2 r
- if (ws < 0)
9 ? K1 q. Z, X% D" {" [2 Z - compareAndSetWaitStatus(node, ws, 0);
3 L+ J* d; y( P% K4 K
# V3 Y/ s* Z, y* k; J# q- /*
& i, w9 H5 G% X$ v2 M+ N: Z. @5 i - * Thread to unpark is held in successor, which is normally0 S4 h# h9 H* h! }3 m5 R
- * just the next node. But if cancelled or apparently null, j2 V; f% A8 b6 k+ h- A& l
- * traverse backwards from tail to find the actual
' ?" H% L' K- i. N; b( p. G - * non-cancelled successor./ p% S$ C2 I1 w) w; V
- */$ y0 ~. y: _; ^2 e& R O& F
- Node s = node.next;9 ], P3 i/ k& W% J9 R
- if (s == null || s.waitStatus > 0) {
2 u$ R$ O* i) z7 b. o# z7 ? - s = null;
0 D# k: V% G5 m q5 o' g! p+ g - for (Node t = tail; t != null && t != node; t = t.prev)3 Q9 @3 _, C3 I7 h. z. |# D" j
- if (t.waitStatus <= 0)* s9 E& o, b+ C* `
- s = t;
" M' c* F( d. ?' A! F% y/ ~ - }
# ]( L. R/ ] O/ B6 b, J - if (s != null)+ r2 F" V @$ u& M7 z# ?) ~, T1 P* y
- LockSupport.unpark(s.thread); }
, J& @! Y s0 h7 W 如果没有合法的数据,从后向前遍历,为什么这么做呢?从前向后不行吗?" u, h* _0 B9 X* P( Z% `
; S7 [- ^+ s l3 u8 I lgd1152已获得悬赏 5 金钱最佳答案
: H0 ]& Y4 m- t+ f" | I/ V5 T+ w. O$ P; {2 P
因为从前往后会遇到空指针
! O5 l+ U5 q- {) E+ [
d' q9 v! z+ Q& V x7 d6 k: L- lgd1152
+ v I; z: M6 i: _ - 发表于2022-01-15
& ]& C9 Z9 ^ J, j8 h0 W - 详细答案 >
' Y1 L% s5 T6 @" N |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|