Home ๐Ÿ’พ [Operating System] Deadlock ๐Ÿ’พ
Post
Cancel

๐Ÿ’พ [Operating System] Deadlock ๐Ÿ’พ

๐Ÿ’พ Deadlock

Deadlock์ด๋ž€ ์ผ์–ด๋‚˜์ง€ ์•Š์„ ์‚ฌ๊ฑด์„ ๊ธฐ๋‹ค๋ฆฌ๋ฉฐ ์ง„ํ–‰์ด ๋ฉˆ์ถฐ๋ฒ„๋ฆฌ๋Š” ํ˜„์ƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์€ Deadlock์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์™€ Deadlock์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ๋ฅผ Resource-Allocation Graph๋กœ ํ‘œํ˜„ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

Resource-Allocation Graph

  • Deadlock์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ
    • Resource A ํ•˜๋‚˜๋ฅผ Process 1์— ํ• ๋‹น
    • Resource A ํ•˜๋‚˜์™€ Resource B ํ•˜๋‚˜๋ฅผ Process 2์— ํ• ๋‹น
    • Process 3์€ Process 1 ๋˜๋Š” Process 2 ์ค‘ ํ•˜๋‚˜์˜ Process์—์„œ Resource A ์‚ฌ์šฉ์ด ๋๋‚˜๋ฉด ํ• ๋‹น ๋ฐ›๊ธฐ ์œ„ํ•ด ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํ™ฉ
  • Deadlock์ด ๋ฐœ์ƒํ•œ ๊ฒฝ์šฐ
    • Process 1์€ Resource A๋ฅผ ํ• ๋‹น ๋ฐ›๊ณ  Process 2์˜ Resource B ์‚ฌ์šฉ์ด ๋๋‚˜๋ฉด ํ• ๋‹น ๋ฐ›๊ธฐ ์œ„ํ•ด ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํ™ฉ
    • Process 2๋Š” Resource B๋ฅผ ํ• ๋‹น ๋ฐ›๊ณ  Process 1์˜ Resource A ์‚ฌ์šฉ์ด ๋๋‚˜๋ฉด ํ• ๋‹น ๋ฐ›๊ธฐ ์œ„ํ•ด ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํ™ฉ

๐Ÿ’พ Deadlock ๋ฐœ์ƒ ์กฐ๊ฑด

Deadlock ๋ฐœ์ƒ ์กฐ๊ฑดDefinition
Mutual Exclusion(์ƒํ˜ธ ๋ฒ ์žฌ)ํ•˜๋‚˜์˜ ์ž์›์„ ํ•œ ๋ฒˆ์— ํ•˜๋‚˜์˜ Process(Thread)๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ
Hold and Wait(์ ์œ ์™€ ๋Œ€๊ธฐ)์ž์›์„ ํ• ๋‹น ๋ฐ›์€ ์ƒํƒœ์—์„œ ๋‹ค๋ฅธ ์ž์›์„ ํ• ๋‹น ๋ฐ›๊ธฐ ์œ„ํ•ด ๊ธฐ๋‹ค๋ฆฌ๋Š” ์ƒํ™ฉ
Nonpreemptive(๋น„์„ ์ )Process(Thread)๊ฐ€ ์ž์›์„ ๋น„์„ ์ ํ•˜๋Š” ์ƒํ™ฉ
Circular Wait(์›ํ˜• ๋Œ€๊ธฐ)Resource-Allocation Graph๊ฐ€ ์›์˜ ํ˜•ํƒœ๋กœ ๊ทธ๋ ค์ง€๋Š” ์ƒํ™ฉ

๐Ÿ’พ Deadlock ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

OS(Operating System)์€ ์˜ˆ๋ฐฉ๊ณผ ํšŒํ”ผ๋ฅผ ํ†ตํ•ด Deadlock์„ ๋ง‰๊ณ  ๊ฒ€์ถœ ํ›„ ํšŒ๋ณต์„ ํ†ตํ•ด ์ด๋ฏธ ๋ฐœ์ƒํ•œ Deadlock์„ ํ•ด๊ฒฐํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’พ Deadlock ์˜ˆ๋ฐฉ

Deadlock์„ ์˜ˆ๋ฐฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ Deadlock ๋ฐœ์ƒ ์กฐ๊ฑด ์ค‘ ํ•˜๋‚˜๋ฅผ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ•˜๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

Deadlock ๋ฐœ์ƒ ์กฐ๊ฑด ์ œ์™ธ์ œ์™ธ ๋ฐฉ๋ฒ•๋‹จ์ 
Mutual ExclusionProcess(Thread)๋“ค์ด ํ•˜๋‚˜์˜ ์ž์›์„ ๊ณต์œ ํ˜„์‹ค์ ์œผ๋กœ ๋ถˆ๊ฐ€๋Šฅ
Hold and WaitOS๋Š” ํŠน์ • Process(Thread)์— ์ž์›์„ ๋ชจ๋‘ ํ• ๋‹นโ€ข ์ž์› ํ™œ์šฉ๋ฅ ์ด ๋‚ฎ์•„์ง
โ€ข ๊ธฐ์•„ ํ˜„์ƒ ๋ฐœ์ƒ
NonpreemptiveProcess(Thread)๊ฐ€ ์ž์›์„ ์„ ์ ํ•˜์—ฌ ์‚ฌ์šฉ๋ฒ”์šฉ์„ฑ์ด ๋–จ์–ด์ง(Ex. ํ”„๋ฆฐํ„ฐ ์ž์›์„ ์„ ์ ํ•˜๊ธฐ ์–ด๋ ค์›€)
Circular Wait์ž์›์— ๋ฒˆํ˜ธ๋ฅผ ๋ถ™์—ฌ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ž์›์„ ํ• ๋‹นโ€ข ๋ชจ๋“  ์ž์›์— ๋ฒˆํ˜ธ๋ฅผ ๋ถ™์ด๋Š” ์ผ์€ ๊ฐ„๋‹จํ•˜์ง€ ์•Š์Œ
โ€ข ๋ฒˆํ˜ธ์— ๋”ฐ๋ผ ํŠน์ • ์ž์›์˜ ํ™œ์šฉ๋ฅ ์ด ๋‚ฎ์•„์งˆ ์ˆ˜ ์žˆ์Œ

๐Ÿ’พ Deadlock ํšŒํ”ผ

OS๋Š” Deadlock์„ ํ•œ์ •๋œ ์ž์›์˜ ๋ฌด๋ถ„๋ณ„ํ•œ ํ• ๋‹น์œผ๋กœ ์ธํ•ด ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ๊ฐ„์ฃผํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— Deadlock์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š์„ ์ •๋„์˜ ์ž์› ์–‘์„ Process(Thread)์— ๋ฐฐ๋ถ„ํ•˜์—ฌ Deadlock์„ ํšŒํ”ผํ•ฉ๋‹ˆ๋‹ค.

Deadlock ์—†์ด Process(Thread)์—๊ฒŒ ์•ˆ์ „ํ•˜๊ฒŒ ์ž์›์„ ํ• ๋‹นํ•  ์ˆ˜ ์žˆ๋Š” ์ˆœ์„œ๋ฅผ ์•ˆ์ „ ์ˆœ์„œ์—ด(Safe Sequence)๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

์ด์ฒ˜๋Ÿผ ์•ˆ์ „ ์ˆœ์„œ์—ด์ด ์žˆ๋Š” ์ƒํƒœ๋ฅผ ์•ˆ์ „ ์ƒํƒœ(Safe State), ์•ˆ์ „ ์ˆœ์„œ์—ด์ด ์—†๋Š” ์ƒํƒœ๋ฅผ ๋ถˆ์•ˆ์ „ ์ƒํƒœ(Unsafe State)๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

Safe State

Unsafe State

๐Ÿ’พ Deadlock ๊ฒ€์ถœ ํ›„ ํšŒ๋ณต

OS๋Š” Process(Thread)๋“ค์ด ์ž์›์„ ์š”๊ตฌํ•  ๋•Œ๋งˆ๋‹ค ๊ทธ๋•Œ๊ทธ๋•Œ ํ• ๋‹นํ•˜๋ฉฐ Deadlock ๋ฐœ์ƒ ์—ฌ๋ถ€๋ฅผ ์ฃผ๊ธฐ์ ์œผ๋กœ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  Deadlock์ด ๊ฒ€์ถœ๋˜๋ฉด ์„ ์ ์„ ํ†ตํ•œ ํšŒ๋ณต์ด๋‚˜ Process(Thread) ๊ฐ•์ œ ์ข…๋ฃŒ๋ฅผ ํ†ตํ•œ ํšŒ๋ณต์„ ํ•ฉ๋‹ˆ๋‹ค.

  • ์„ ์ ์„ ํ†ตํ•œ ํšŒ๋ณต: Deadlock์ด ํ•ด๊ฒฐ๋  ๋•Œ๊นŒ์ง€ ๋‹ค๋ฅธ Process(Thread)๋กœ๋ถ€ํ„ฐ ์ž์›์„ ๊ฐ•์ œ๋กœ ๋นผ์•—๊ณ  ํ•œ Process(Thread)์—๊ฒŒ ์ž์›์„ ๋ชฐ์•„์ฃผ๋Š” ๋ฐฉ์‹
  • Deadlock์— ๋†“์ธ ๋ชจ๋“  Process(Thread)๋ฅผ ๊ฐ•์ œ ์ข…๋ฃŒ๋ฅผ ํ†ตํ•œ ํšŒ๋ณต: ๋งŽ์€ Process(Thread)๋“ค์ด ์ž‘์—… ๋‚ด์—ญ์„ ์žƒ๊ฒŒ ๋จ
  • Deadlock์ด ์—†์–ด์งˆ ๋•Œ๊นŒ์ง€ ํ•˜๋‚˜์˜ Process(Thread)์”ฉ ๊ฐ•์ œ ์ข…๋ฃŒ๋ฅผ ํ†ตํ•œ ํšŒ๋ณต: Deadlock์ด ์—†์–ด์กŒ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๋Š” ๊ณผ์ •์—์„œ Overhead๊ฐ€ ์•ผ๊ธฐ๋จ
This post is licensed under CC BY 4.0 by the author.

๐Ÿ’พ [Operating System] Synchronization ๐Ÿ’พ

๐Ÿ’พ [Operating System] Virtual Memory ๐Ÿ’พ