[OS] Concurrency: Deadlock & Starvation

seunghyunΒ·2023λ…„ 3μ›” 7일
0

πŸ’»

λͺ©λ‘ 보기
4/16

concurrency (λ™μ‹œμ„±)

2개 μ΄μƒμ˜ μŠ€λ ˆλ“œ (ν˜Ήμ€ ν”„λ‘œμ„ΈμŠ€)κ°€ λ™μ‹œμ— μ‹€ν–‰λ˜λŠ” μƒνƒœμ΄λ‹€.
1개의 CPUκ°€ μ—¬λŸ¬ μŠ€λ ˆλ“œλ₯Ό λ²ˆκ°ˆμ•„ μ‹€ν–‰ν•  λ•Œ λ‚˜νƒ€λ‚œλ‹€.

parallelism (병렬성)

2개 μ΄μƒμ˜ μŠ€λ ˆλ“œκ°€ μ„œλ‘œ λ‹€λ₯Έ CPU μƒμ—μ„œ 같은 μ‹œκ°„μ— λ™μ‹œμ— μ‹€ν–‰λ˜λŠ” 병렬성이닀.


Deadlock

πŸ’‘ a set of processes is deadlocked when each process in the set is blocked awaiting an event (or a recource) that can only be triggered (released) by another blocked process in the set

Two general categories of resources

βœ”οΈ Reusable resource

  • Can be safely used by only one process at a time and is not depleted by that use
  • ex) processors, memorym I/O devices, files, database and semaphores

βœ”οΈ Consumable resource

  • Can be created (produced) and destroyed (consumed)
  • Typically, there is no limit on the number of consumable resources
  • ex) interrupts, signals, messages, data in I/O buffers

Conditions or Deadlock

λ°λ“œλ½μ΄ λ°œμƒν•˜λŠ” 쑰건!

The first three conditions are necessary but not sufficient conditions for a deadlock.

The fourth condition is actually a consequence of the first three.

Given that the first three condition exist, a sequence of events may occur that lead to an unresolvable circular wait.

βœ”οΈ Mutual exclusion

  • Only one process may use a resource at a time

βœ”οΈ Hold and wait

  • A process may hold allocated resources when waiting for the other resources
    • Nothing or All

βœ”οΈ No preemption

  • No resource can be forcibly removed from a process holding it κ°•μ œλ‘œ 뺏을 수 없을 λ•Œ

βœ”οΈ Circular wait

  • A closed chain of processes exists such that each process holds at least one resource needed by the next process in the chain

Three Approaches for Deadlocks

λ°λ“œλ½μ„ ν•΄κ²°ν•˜κΈ° μœ„ν•œ 3가지 λ°©μ•ˆ

βœ”οΈ Deadlock prevention

  • κ°€μž₯ 보수적이고 λΉ„νš¨μœ¨μ μΈ 방법
  • Adopt a policy that eliminated one of the conditions 1 through 4

βœ”οΈ Deadlock avoidance

  • 쀑도
  • Make the appropriate choices dynamically based on the current state of resource allocation

βœ”οΈ Deadlock detection

  • 내버렀둬~ 주기적으둜 κ°μ§€ν•˜κΈ°
  • Allow the deadlock to occur, attempt to detect the presence of deadlock, and recover if a deadlock is detected

πŸ”— Reference

[KUOCW] 졜린 κ΅μˆ˜λ‹˜μ˜ 운영체제 κ°•μ˜λ₯Ό μˆ˜κ°•ν•˜κ³  μ •λ¦¬ν•œ λ‚΄μš©μž…λ‹ˆλ‹€. 잘λͺ»λœ λ‚΄μš©μ΄ μžˆλ‹€λ©΄ λŒ“κΈ€λ‘œ μ•Œλ €μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€ 😊

0개의 λŒ“κΈ€