[Java] 멀티 스레드 동기화(multi-threaded synchronization)
임계 구역(critical section)과 세마포어(semaphore) critical section은 여러 개의 thread가 동시에 접근할 수 없는 영역이다 semaphore는 특별한 형태의 시스템 객체이며 get/release 두 개의 기능이 있다 한 순간 오직 하나의 thread 만이 semaphore를 얻을 수 있고 나머지 thread들은 대기(blocking) 상태가 된다 semaphore를 얻은 thread 만이 critical section에 들어갈 수 있다 Kh 클래스와 Ys 클래스가 동시에 Bank 클래스에 접근하는 예제 package ch22; class Bank { private int money = 5000; public synchronized void saveMoney(int ..
2022.02.27