Skip to content

Commit

Permalink
改进原子Boolean的并发锁实现,空循环提示放弃CPU调度
Browse files Browse the repository at this point in the history
  • Loading branch information
xuMingHai1 committed May 6, 2022
1 parent 2c58b6a commit cd81928
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ private static class SimpleLook {
private void look() {
// 当已经有线程获取到锁时,进行循环等待释放锁
while(!atomicBoolean.get()) {

// 提示当前线程愿意放弃其当前对处理器的使用。
Thread.yield();
}

// 从循环中结束表示,锁已经释放开始争抢锁
Expand Down

0 comments on commit cd81928

Please sign in to comment.