CAS唤醒后继线程 为什么是从后向前遍历5金钱.anslist{background:url(sourc
技术问答
359 人阅读
|
0 人回复
|
2023-09-11
|
8 ]: m! q; y5 ^! C0 ?
- private void unparkSuccessor(Node node) {+ A7 T& _; ]! k; i$ f
- /** N- u2 I9 B( C1 d# G: s
- * If status is negative (i.e., possibly needing signal) try
+ p9 |, v w3 G1 j - * to clear in anticipation of signalling. It is OK if this/ T1 {& |$ r5 z+ h0 _1 f- |( G
- * fails or if status is changed by waiting thread.: H. M& B- x& L" m2 l* L/ K
- */
0 v; ]2 ^1 i, Y - int ws = node.waitStatus;
- a! E: W/ H, D6 K - if (ws < 0)
" x5 g8 y' P$ C$ T ]' s. S - compareAndSetWaitStatus(node, ws, 0);
7 B2 B! y9 |) D) N; i - * R% E9 `3 R, e* L
- /*
( J. W; S( X( Q7 l5 Z" ^: Q2 J3 P - * Thread to unpark is held in successor, which is normally
7 ^. t% C+ N! i5 c! @ - * just the next node. But if cancelled or apparently null,
9 d. W/ ]' o2 L& Z$ [# k$ F% D - * traverse backwards from tail to find the actual$ g! g$ D& \' R K$ b6 l: h
- * non-cancelled successor.2 Z' o; @" S* _# I+ Q& p
- */
l1 I' c; V: L- J! s) B6 e - Node s = node.next;( {& }, Z6 U) N+ m
- if (s == null || s.waitStatus > 0) {
2 [% u# F7 l% \! Y# j) | - s = null;5 m# o/ N8 \4 a
- for (Node t = tail; t != null && t != node; t = t.prev)
4 I4 j& H$ p4 M& F h+ R3 C6 {3 G - if (t.waitStatus <= 0)3 B. ]6 o4 U' |* O, O- m! i/ J
- s = t;. }9 L8 I3 @. P4 N# h9 B- d, Z
- }
+ u8 F1 K: {4 `2 R - if (s != null)
* D) E2 [% c) X; {5 A$ w1 ]: H - LockSupport.unpark(s.thread); }
: l- r \9 H r) B, ?6 c 如果没有合法的数据,从后向前遍历,为什么这么做呢?从前向后不行吗?
4 w* u1 C) G0 [# @& `我知道答案 回答被采纳将会获得5 金钱 已有0人回答 |
|
|
|
|
|