📌HW를 이용하여 ME 구현
📖TestAndSet instruction
- Test, Set을 한번에 하는 기계어
- machine instruction
- 실행 중 인터럽트 받지 않음, preemption 되지않음
- 단, 3개이상의 프로세스에대해 bounded waiting 위배
boolean TestAndSet (boolean *target) {
boolean temp = *target;
*target = true;
return temp;
}

📖N-process ME

❗️HW solution of ME 특징
📌OS를 이용하여 ME 구현
📖spinLock
- S 초기화, P(), V() 연산으로만 접근 가능 (정수형 변수 S)
- 위 연산들은 atomic 즉, preemption 되지않게 OS가 보장
- 멀티 프로세서에서만 사용 가능
- busy waiting
P(S) {
while (S<=0) do
endWhile;
S = S-1
}
V(S) {
S = S+1
}

📖semaphore
- S 초기화, P(), V() 연산으로만 접근 가능 (정수형 변수 S)
- 위 연산들은 atomic 즉, preemption 되지않게 OS가 보장
- 차이점 : S변수에 대응하는 ready queue 할당
P(S) {
if (S>0)
then S = S - 1;
else wait on the queue;
}
V(S) {
if (waiting process on queue)
then wake up one of them;
else S = S + 1;
}
binary semaphore
- S가 0 또는 1
- ME, 동기화 목적으로 사용
counting semaphore
- S가 0이상의 정수값 가질 수 있음
- producer - consumer 문제 해결
📚semaphore로 해결 가능한 문제들
- 상호배제 문제
- 프로세스 동기화 문제
- 생산자-소비자 문제
- Reader-writer 문제
- Dining philosopher problem
프로세스 동기화 문제
- 프로세스의 실행 순서 맞추기
- 프로세스들은 병행적이며, 비동기적으로 수행

생산자-소비자 문제
Reader-writer 문제
- Reader : 데이터 읽기 연산 수행
- Writer : 데이터 갱신 연산 수행
- Reader들은 동시에 데이터 접근 가능
- Writer들은 동시에 데이터 접근 불가
- Reader, Writer은 동시에 데이터 접근 불가

❗️Semaphore 특징
- No busy waiting : 기다려야하는 프로세스는 block상태로 기다림
- semaphaore queue에 대한 wake-up 순서는 비결정적 즉, starvation problem