| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -568,10 +568,12 @@ private void incrementAndPrint(int targetValue) { | |||
| 568 | 568 | return; | |
| 569 | 569 | } | |
| 570 | 570 | // 尝试 CAS 操作:如果当前值等于 targetValue - 1,则原子地设置为 targetValue | |
| 571 | - if (unsafe.compareAndSwapInt(this, fieldOffset, currentValue, targetValue)) { | ||
| 572 | - // CAS 成功后立即打印,确保打印的就是本次设置的值 | ||
| 573 | - System.out.print(targetValue + " "); | ||
| 574 | - return; | ||
| 571 | + if (currentValue == targetValue - 1) { | ||
| 572 | + if (unsafe.compareAndSwapInt(this, fieldOffset, currentValue, targetValue)) { | ||
| 573 | + // CAS 成功后立即打印,确保打印的就是本次设置的值 | ||
| 574 | + System.out.print(targetValue + " "); | ||
| 575 | + return; | ||
| 576 | + } | ||
| 575 | 577 | } | |
| 576 | 578 | // CAS 失败,重新读取并重试 | |
| 577 | 579 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments