λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
⭐ Group_Study/Operating System

[3μ£Όμ°¨] Process Synchronization and Mutual Exclusion

by ν¬μŠ€νŠΈμ‰μ΄ν¬ 2022. 12. 16.

ν”„λ‘œμ„ΈμŠ€ 동기화 & μƒν˜Έλ°°μ œ (Process Synchronization and Mutual Exclusion)

Process Synchronization

βœ” 닀쀑 ν”„λ‘œκ·Έλž˜λ° μ‹œμŠ€ν…œ

  • μ—¬λŸ¬ 개의 ν”„λ‘œμ„ΈμŠ€ 쑴재
  • ν”„λ‘œμ„ΈμŠ€λ“€μ€ μ„œλ‘œ λ…λ¦½μ μœΌλ‘œ λ™μž‘
  • 곡유 μžμ› λ˜λŠ” 데이터가 μžˆμ„ λ•Œ, 문제 λ°œμƒ κ°€λŠ₯

βœ” 동기화(Synchronization)

  • ν”„λ‘œμ„ΈμŠ€λ“€μ΄ μ„œλ‘œ λ™μž‘μ„ λ§žμΆ”λŠ” 것
  • ν”„λ‘œμ„ΈμŠ€λ“€μ΄ μ„œλ‘œ 정보λ₯Ό κ³΅μœ ν•˜λŠ” 것

Asynchronous and Concurrent P's

βœ” 비동기적(Asynchronous)

  • ν”„λ‘œμ„ΈμŠ€λ“€μ΄ μ„œλ‘œμ— λŒ€ν•΄ λͺ¨λ¦„

βœ” 병행적 (Concurrent)

  • μ—¬λŸ¬ 개의 ν”„λ‘œμ„ΈμŠ€ 듀이 λ™μ‹œμ— μ‹œμŠ€ν…œμ— 쑴재

βœ” 병행 μˆ˜ν–‰μ€‘μΈ 비동기적 ν”„λ‘œμ„ΈμŠ€λ“€μ΄ 곡유 μžμ›μ— λ™μ‹œ μ ‘κ·Όν•  λ•Œ λ¬Έμ œκ°€ λ°œμƒν•  수 있음

Terminologies

βœ” shared data (곡유 데이터) or Critical data

  • μ—¬λŸ¬ ν”„λ‘œμ„ΈμŠ€λ“€μ΄ κ³΅μœ ν•˜λŠ” 데이터

βœ” Critical section (μž„κ³„ μ˜μ—­)

  • 곡유 데이터λ₯Ό μ ‘κ·Όν•˜λŠ” μ½”λ“œ μ˜μ—­ (code segment)

βœ” Mutual exclusion(μƒν˜Έ 배제)

  • λ‘˜ μ΄μƒμ˜ ν”„λ‘œμ„ΈμŠ€κ°€ λ™μ‹œμ— critical section에 μ§„μž…ν•˜λŠ” 것을 λ§‰λŠ” 것

Critical section (example)

βœ” sdata: shared data

 

βœ” 기계어 λ²ˆμ—­ κ²°κ³Ό
βœ” Race condition: μ‹€ν–‰ μˆœμ„œμ— λ”°λΌμ„œ 값이 달라진닀!

Mutual Exclusion (μƒν˜Έ 배제)

Mutual Exclusion Methods

βœ” Mutual exclusion primitives(κΈ°λ³Έ μ—°μ‚°)

  • enterCS() primitive
    • Critical section μ§„μž… μ „ 검사
    • λ‹€λ₯Έ ν”„λ‘œμ„ΈμŠ€κ°€ critical section μ•ˆμ— μžˆλŠ”μ§€ 검사
  • exitCS() primitive
    • Critical section을 λ²—μ–΄λ‚  λ•Œμ˜ ν›„μ²˜λ¦¬ κ³Όμ •
    • Critical section을 벗어남을 μ‹œμŠ€ν…œμ΄ μ•Œλ¦Ό

Requirements for ME primitives

βœ” Mutual exclusion(μƒν˜Έ 배제)

  • Critical section(CS)에 ν”„λ‘œμ„ΈμŠ€κ°€ 있으면, λ‹€λ₯Έ ν”„λ‘œμ„ΈμŠ€μ˜ μ§„μž…μ„ κΈˆμ§€

βœ” Progress(진행)

  • CS μ•ˆμ— μžˆλŠ” ν”„λ‘œμ„ΈμŠ€ μ™Έμ—λŠ”, λ‹€λ₯Έ ν”„λ‘œμ„ΈμŠ€κ°€ CS에 μ§„μž…ν•˜λŠ” 것을 λ°©ν•΄ ν•˜λ©΄ μ•ˆλ¨

βœ” Bounded waiting(ν•œμ • λŒ€κΈ°)

  • ν”„λ‘œμ„ΈμŠ€μ˜ CS μ§„μž…μ€ μœ ν•œ μ‹œκ°„ 내에 ν—ˆμš©λ˜μ–΄μ•Ό 함

Two Process Mutual Exclusion

version 1

βœ” turn κ°œλ… ν™œμš©

βœ” Progress 쑰건 μœ„λ°°!

  • P0이 critical section에 μ§„μž…ν•˜μ§€ μ•ŠλŠ” 경우
  • ν•œ Processκ°€ 두 번 연속 CS에 μ§„μž… λΆˆκ°€

version 2

βœ” flag ν™œμš©

βœ” Mutual exclusion 쑰건 μœ„λ°°

version 3

βœ” Progress, Bounded waiting 쑰건 μœ„λ°°

λŒ“κΈ€