
Read-modify-write race condition example

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

key 가 있는 상황에서 동시에 if 문을 실행하고
동시에 지운다
한 쓰레드 에서는 val 이 null이 될 수 있다.
Check-then-act solution with atomic, synchronized block
map을 monitor로 하는 synchronized 을 설정하자!