HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
🧵
멀티쓰레드, 동시성 프로그래밍
/
🧵
Java Concurrency and Multithreding
/
Race Conditions in Java MultiThreading

Race Conditions in Java MultiThreading

notion image

Read-modify-write race condition example

notion image
 

Read-modify-write solution with atomic, synchronized block

  • Critical Section을 Atomic하게 하여 Sequential Access를 보장 할 수 있다.
  • Critical Section을 synchronized block으로 감싸자!
 

One thread writes, one thread reads - example

  • Race Condition 안생김
  • 하지만 이론적으론 생길 수 있다?
 

Two threads that access same objects, but not write to the same objects.

  • Race Condition 안생김
  • 하지만 이론적으론 생길 수 있다?
 
 
 

Check-then-act solution with atomic, synchronized block

notion image
key 가 있는 상황에서 동시에 if 문을 실행하고
동시에 지운다
한 쓰레드 에서는 val 이 null이 될 수 있다.

Check-then-act solution with atomic, synchronized block

map을 monitor로 하는 synchronized 을 설정하자!