Problems
Cooperating threads
- Indep threads:
- deterministic
- no shared states
- but shared files might exist
- reproducible
- order does not matter
- Cooperating threads
- shared state
- non-det
- non-rep.
it means: 디버깅이 불가능에 가깝다!!
Race condition 경쟁 상태
둘 이상의 입력 또는 조작의 타이밍이나 순서 등이 결과값에 영향을 줄 수 있는 상태를 말한다. 입력 변화의 타이밍이나 순서가 예상과 다르게 작동하면 정상적인 결과가 나오지 않게 될 위험이 있는데 이를 경쟁 위험이라고 한다
- shared state에 여러 스레드가 동시에 접근하면 “Data inconsistency”가 발생할 수 있다.
- 아주 작은 타이밍 차이로도 발생하여 찾기가 어렵다
- 다 안썼는데 읽는다는지…
Race condition: Atomicity
Operation runs to completion without interruption
- 원자성: inst는 시작했으면 끊기지 않고(indivisibly) 완료되어야 한다.
- 그 실행중인 구간을 “Critical section”이라고 한다.
- 어떻게 구현할 수 있을까?
- 스레드 실행 순서는 non deterministic한데?
- 하드웨어 수준에서 순서를 바꾸기? (아키때배운 RAR 등등..)
- multi-word operation is NOT atomic?
따라서, 공유 자원에 대한 synchronization이 필요하다.
Example: Too-Much-Milk Problem

solution: note