SSAFY-CSStudy / OS

SSAFY CS 운영체제 스터디입니다.
12 stars 0 forks source link

[5. 병행제어1] Synchronization hardware의 Test_and_Set 함수 #13

Open Yunhee000 opened 7 months ago

Yunhee000 commented 7 months ago

Test_and_Set 코드

bool Test_and_Set(bool target) {
  bool rv = target;
  target = true;
  return rv;
}

Synchronization Hardware

하드웨어적으로 test & modify를 atomic하게 수행할 수 있도록 지원 -> 데이터를 읽어가는 것과 저장하는 것 모두 한꺼번에 수행

do {
    while (Test_and_Set(lock));
    critical section
    lock = false;
    remainder section
} whlie (1);

=> lock이 false이면 아무도 critical section에 들어가지 않음