ch6. Deadlock(๋ฐ๋“œ๋ฝ) #์šด์˜์ฒด์ œOS #๋ฐ๋“œ๋ฝ์˜์กฐ๊ฑด

2022. 12. 14. 02:01ใ†_Study/OperationSystem

728x90

Concurrency : Deadlock  ๐Ÿ‡¸.•*¨*•¸.•*¨*•¸.•*¨*•¸.•*¨*•

ํ•ด๋‹น ์ž๋ฃŒ๋Š” ๊ฐ•์˜ ํ•™์Šต์ž๋ฃŒ์ž…๋‹ˆ๋‹ค.


์•„๋ž˜์˜ ์„ธ ํ”„๋กœ์„ธ์Šค๋Š” ํ˜„์žฌ ๋ฐ๋“œ๋ฝ(deadlock) ์ƒํ™ฉ์ด๋‹ค. process 1์€ ์ž์› 1์„ ๊ฐ€์ง€๊ณ  ์ž์› 2๋ฅผ ์š”์ฒญํ•˜๋Š” ์ค‘์ธ๋ฐ ์ด๋•Œ ์š”์ฒญ์ด ๋ฐ›์•„๋“ค์—ฌ์ง€์ง€ ์•Š์œผ๋ฉด ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„˜์–ด๊ฐˆ ์ˆ˜ ์—†๋‹ค. ์ฆ‰, P1์€ ๋‹ค์Œ์˜ ์š”์ฒญ์„ ๊ธฐ๋‹ค๋ฆฌ๊ณ  ๋Œ€๊ธฐํ•˜๊ณ  ์žˆ๋‹ค. P2, P3๋„ ๋™์‹œ์— ์š”์ฒญ์„ ๊ธฐ๋‹ค๋ฆฌ๊ณ  ์žˆ์„ ๋•Œ ๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋‹ค์Œ ๋‹จ๊ณ„๋กœ ๋„์ €ํžˆ ๋„˜์–ด๊ฐ€์ง€ ๋ชปํ•˜์—ฌ ๋ฉˆ์ถฐ์žˆ๋Š” ์ƒํ™ฉ, state์— ๋ณ€ํ™”๊ฐ€ ์—†๋Š” ์ƒํ™ฉ์„ ๋ฐ๋“œ๋ฝ์ด๋ผ๊ณ  ํ•œ๋‹ค.

 ์šด์˜์ฒด์ œ์™€ ํ”„๋กœ์„ธ์„œ ๊ฐ„์˜ ๋ ˆ๋ฒจ ์ฐจ์ด ๋•Œ๋ฌธ์— ์ง์ ‘์ ์œผ๋กœ ์ผ์–ด๋‚˜์ง€ ์•Š๊ฒ ์ง€๋งŒ deadlock ์ด ๋ฐœ์ƒํ•˜๊ธฐ ์ „์— ์กฐ์น˜๋ฅผ ์ทจํ•ด์•ผ ํ•œ๋‹ค.

 

System models

๋‘ ๊ฐ€์ง€์˜ Model๋กœ ํ˜„์žฌ ์ƒํ™ฉ์„ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. P-R Model ๊ณผ S-T Model์ธ๋ฐ ๋‘˜ ์˜ ์ฐจ์ด๋ฅผ ์ž˜ ์ดํ•ดํ•ด์•ผ ํ•œ๋‹ค.

Process-Resource Model

: ํ”„๋กœ์„ธ์Šค์™€ ๋ฆฌ์†Œ์Šค์˜ ์ง‘ํ•ฉ์œผ๋กœ ๊ตฌ์„ฑ P, R

: Cj: number of units of Rj in the system (๋ฆฌ์†Œ์Šค์˜ ๊ฐœ์ˆ˜)

: ใ…์™€ O๋กœ ์ด๋ฃจ์–ด์ง„ ๋ชจํ˜•์œผ๋กœ ๊ทธ๋ฆฐ๋‹ค. ๊นŒ๋งŒ ๋™๊ทธ๋ผ๋ฏธ๊ฐ€ resource

 

 

 

 

 

 

State_Transition Model : ์ƒํƒœ ์ „์ด ๋ชจ๋ธ

: S : ํ˜„์žฌ ์ƒํƒœ, ํ”„๋กœ์„ธ์Šค๋“ค์ด ๋™์ž‘ํ•˜๋ฉด ์ƒํƒœ๊ฐ€ ๋ฐ”๋€Œ๋Š”๋ฐ ์ด ์ƒํƒœ๋“ค์˜ ์ง‘ํ•ฉ

: ํ”„๋กœ์„ธ์Šค์™€ ๋ฆฌ์†Œ์Šค์˜ ์ƒ์„ธ๋ฅผ ์ž์„ธํžˆ ๋ณด์ง€ ์•Š์ง€๋งŒ, ์ƒํƒœ๋“ค์˜ ์ง‘ํ•ฉ์œผ๋กœ ํ‘œํ˜„ํ•œ๋‹ค.

: state changes when processes take action

: This allows us to indentfy a deadlock situation in the operating system.

 

 

 

 

 

 

 

 

 

์ƒํƒœ ์ „์ด๋Š” process์˜ action์— ์˜ํ•ด system ๋ณ€ํ•  ์ˆ˜ ์žˆ์Œ์„ ์˜๋ฏธํ•˜๊ณ  3๊ฐ€์ง€์˜ ํ–‰๋™(๋ฐฉ๋ฒ•)์ด ์žˆ๋‹ค.

 

์ƒํƒœ๋ฅผ ๋ณ€ํ™”ํ•˜๋Š” action์—๋Š” 3 ๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

- request : request one or more units of a resource : ๋ฆฌ์†Œ์Šค๋ฅผ ์š”์ฒญ

- allocation : All outstanding requests from a process for a given resource are satisfied. : ๋ฆฌ์†Œ๋ฅผ ํ• ๋‹น

- deallocation : the process release units of a resoucre. : ๋ฆฌ์†Œ๋ฅด๋ฅผ ๋Œ๋ ค์คŒ(๋‚ด๋†“๊ธฐ)

 

 

P2 ์— ์˜ํ•ด ๋ณ€๊ฒฝ๋˜๋Š” ์ƒํƒœ๊ฐ€ ์—†๋‹ค๋ฉด p2๋Š” block๋˜์—ˆ๋‹ค๊ณ  ๋งํ•œ๋‹ค.

 

์ƒํƒœ ์ „์ด ๋ชจ๋ธ๋กœ deadlock ํ™•์ธํ•˜๊ธฐ

 

 

 

deadlock ์„ ๋ง‰๋Š” ๋ฐฉ๋ฒ• : deadlock์ด ๋ฐœ์ƒํ•˜๋Š” ์กฐ๊ฑด 4๊ฐ€์ง€ ์ค‘์— ํ•˜๋‚˜๋ผ๋„ ๋ถˆ๋งŒ์กฑํ•˜๋ฉด ๋œ๋‹ค.

- Prevention : ์˜ˆ๋ฐฉ , deadlock์ด ๋ฐœ์ƒํ•˜์ง€์•Š๋„๋ก ์‹œ์Šคํ…œ์„ ์„ค๊ณ„ -> deadlock์˜ ์กฐ๊ฑด์„ ์•Œ์•„์•ผํ•จ (4๊ฐ€์ง€)

- Avoidance : ํšŒํ”ผ , deadlock๊นŒ์ง€ ์ง„ํ–‰ํ•˜์ง€ ์•Š๋Š” ๋ชจ๋ธ์„ ์„ค๊ณ„ํ•˜๊ณ  ์ „๋žต์„ ์„ค์ • -> ์˜ˆ์ธกํ•˜๊ธฐ ์œ„ํ•ด์„œ action ์ •๋ณด์™€ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์ด ํ•„์š”ํ•˜๋‹ค.

- Detection & Recovery : ๊ฐ์ง€, ํšŒ๋ณต : ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ชจ๋‹ˆํ„ฐ๋ง ํ•˜๋Š” ํ•จ์ˆ˜(๋ฐฑ๊ทธ๋ผ์šด๋“œ)

- Manual intervention :  ์ •์•ˆ๋˜๋ฉด ๊ป๋‹ค ์ผœ๊ธฐ(Reboot)

 

 

deadlock์˜ ์กฐ๊ฑด 4๊ฐ€์ง€

- mutual exclusion : ํ•œ ๋ฒˆ์— CS๋Š” ํ•˜๋‚˜๋งŒ ์‹คํ–‰ํ•œ๋‹ค. ๋ฐ˜๋“œ์‹œ ์ง€์ผœ์•ผํ•  ์กฐ๊ฑด์ด๋‹ค.

- hold and wait : ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ๊ธฐ๋‹ค๋ฆฐ๋‹ค.  

- circular waiting : ์›ํ˜•์˜ ๋ชจ์–‘์„ ์œ ์ง€ํ•œ๋‹ค.

- No preemption : ์„ ์  ๋˜๋Š” ์ทจ์†Œ๋ฅผ ํ•˜์ง€ ์•Š๋Š”๋‹ค. -> ์š”์ฒญ์„ ๊ณ„์† ๊ธฐ๋‹ค๋ฆฐ๋‹ค. ์šฐ์„ ์ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด block์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

Hold and Wait :Need to be sure a process does not hold one resource while requesting another

ํ•„์š”ํ•œ๊ฒŒ ์žˆ์œผ๋ฉด ํ•œ๊บผ๋ฒˆ์— ์š”์ฒญํ•˜๊ธฐ

 

์•„๋ž˜๋ฅผ ํ–ฅํ•œ ํ™”์‚ดํ‘œ์ฒ˜๋Ÿผ ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค์˜ action์—๋„ ์ƒํ™ฉ์ด ๋ฐ”๋€” ์ˆ˜๋„ ์žˆ์ง€๋งŒ ๋ชจ๋“  ๋ฆฌ์†Œ์Šค์˜ ์š”์ฒญ์„ ํ•œ ๋ฒˆ์— ์ง„ํ–‰ํ•˜๋ฉด ๋ฐ๋“œ๋ฝ์€ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Approach 1: Force process to request all resources it needs at one time.

ํ•œ ๋ฒˆ์— ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋ฅผ ํ• ๋‹น ๋ฐ›๋Š”๋‹ค.

Approach 2: If a process needs to acquire a new resource, it must first release all resources it holds, then reacquire all it needs.

์ƒˆ๋กœ์šด ๋ฆฌ์†Œ์Šค๊ฐ€ ํ•„์š”ํ•˜๋ฉด ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๋ฅผ ๋‚ด๋ ค๋†“๊ณ  ๋‹ค์‹œ ์š”์ฒญํ•œ๋‹ค.

 

์ด๋Ÿฐ ๋ชจ๋ธ์€ ๋งŒ๋“  ์ด์œ ๋Š” ์‹œ์Šคํ…œ์„ ์ •์˜ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ๋ฐ๋“œ๋ฝ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š” ์„ค๊ณ„๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ ๋จผ์ € ๊ฐœ๋…์ ์ธ ์ •์˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

 

ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฉด์„œ ๋‹ค๋ฅธ ๊ฒƒ์„ ์š”๊ตฌํ•˜์—ฌ ๋ฐœ์ƒํ•˜๋Š” ๊ผฌ์ด๊ณ  ๊ผฌ์ธ ๋ชจ์–‘์˜ ๋ฐ๋“œ๋ฝ์„ ์‚ฌ์ „์— ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

Circular wait : Have a situation in which there are N processes holding units of N resources

๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๋ฅผ ์ˆœ์„œ๋ฅผ ๋งค๊ธด๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ์ž์‹ ์˜ ์ˆซ์ž๋ณด๋‹ค ๋†’์€ ํ”„๋กœ์„ธ์Šค์—๊ฒŒ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๋‹ค.

 

O๊ฐ€  process, ใ…๊ฐ€ Resources

R -> P : Hold : ์‹ค์„ 

P -> R : request : ์ ์„ 

 

์ฒ ํ•™์ž๋“ค์˜ ์ €๋…์‹์‚ฌ์— ์ ์šฉํ•˜๋ฉด : ์›์˜ ํ˜•ํƒœ์˜ ์š”์ฒญ์˜ ๋ฐฉ์‹ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•จ.

-> ๋งˆ์ง€๋ง‰ ์ˆซ์ž์ธ 4์˜ ๋ฐœ์ƒ ์ˆœ์„œ๋ง ์ž˜ ๋ฐฐ์น˜ํ•˜๋ฉด ๋œ๋‹ค.

 

Circular wait (cont')

 

There is a cycle in the graph of processes and resources

choose a resource request strategy by which no cycle will be introduced

์ผ์ข…์˜ ์ „๋žต์„ ์ทจํ•œ๋‹ค.

 

Total order on all resources, then can only ask for Rj if Ri < Rj for all Ri the process is currently holding.

 

 

Allow Preemption

Allow a process to time-out on a blockes request - withdrawing(Wu) the request if it fails

 

request ์ „์œผ๋กœ ์ทจ์†Œํ•˜๋Š” ๊ฒƒ์„ ์ถ”๊ฐ€ํ•˜์˜€๋‹ค. -> Si๋กœ ๋‹ค์‹œ ๋Œ์•„์˜จ๋‹ค. ๋‚ด๊ฐ€ ์ทจ์†Œํ•˜๋ฉด ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋„ ์ƒํƒœ๋ฅผ ๋ณ€ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. -> ์ด์ •๋„์˜ ์šฐ์„ ์ˆœ์œ„ ๋ณ€ํ™”๋„ ์ถฉ๋ถ„ํ•˜๋‹ค.

 

deadlock์€ ์•„๋‹Œ๋ฐ deadlock ์ฒ˜๋Ÿผ ๋ณด์ด๋Š” ํ˜„์ƒ : ๋จธ๋ฌผ๋Ÿฌ์žˆ๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ด์ง€๋งŒ, ๊ณ„์† ์™”๋‹ค๊ฐ”๋‹ค ์–‘๋ณดํ•˜๋ฉด์„œ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ์ด๋‹ค.

Livelock :์„œ๋กœ์–‘๋ณดํ•˜๊ธฐ : two or more processes continually repeat the ame interaction in response to changes in the other processes without doing any useful work

- These processes are not in the waiting state, and they are running concurrently.

- This is different from a deadlock because in a deadlock all processes are in the waiting state.

 

 

 

 

Deadlock Avoidance : ๋ฐ๋“œ๋ฝ ํšŒํ”ผ  

deadlock๊นŒ์ง€ ์ง„ํ–‰ํ•˜์ง€ ์•Š๋Š” ๋ชจ๋ธ์„ ์„ค๊ณ„ํ•˜๊ณ  ์ „๋žต์„ ์„ค์ • -> ์˜ˆ์ธกํ•˜๊ธฐ ์œ„ํ•ด์„œ action ์ •๋ณด์™€ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์ด ํ•„์š”ํ•˜๋‹ค.

 

Define a model of system states , then choose a strategy that will guarantee that the system will not go to a deadlock state

 

Requires extra inforamation, e.g., the maximum claim for each process

์ตœ๋Œ€ ์š”๊ตฌ๋Ÿ‰์„ ๊ณ„์‚ฐํ•œ๋‹ค.

 

Allows resouce manager to see the worst case that could happen, then to allow transitions based on that knowledge.

๋ฆฌ์†Œ์Šค๊ด€๋ฆฌ์ž(OS)๊ฐ€ worst case๊ฐ€ ์ผ์–ด๋‚˜๋Š”์ง€ ํ•ญ์ƒ ๊ฐ์‹œํ•˜๊ณ  ์žˆ๋‹ค. 

- the resource is available :๋ฆฌ์†Œ์Šค๋Š” ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

- Even if all processes use ther maximun reosources, : ๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ตœ๋Œ€ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

- Finally, when a state transition that can complete the execution of all processes in the system is possible : ๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ˆ˜ํ–‰์ค‘์— ์ตœ๋Œ€์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ƒํ™ฉ์„ ์‚ฌ์šฉํ•˜๋”๋ผ๋„ ์•ˆ์ „ํ•œ ์ƒํƒœ๋ผ๋ฉด ์ด๋ฅผ ํ—ˆ์šฉํ•œ๋‹ค.

 

์ƒํƒœ๋ฅผ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์žˆ์–ด์•ผํ•˜๋Š”๋ฐ 2๊ฐ€์ง€๋กœ ๋‚˜๋ˆˆ๋‹ค.

 

Safe vs UnSafe states

safe state: one in which the system can assure that any sequence of subsequent transitions leads back to the initial state : init์œผ๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ƒํ™ฉ

- Even if all exercies their maximun claim, there is an allocation strategy by which all claims can be met.

 

Unsafe state: one in which the system cannot gurantee that the system will transition block to the initial state.

- unsafe stste can lead to a dead lock state if too many processes exercise their maximum claim at once.

 

์ดˆ๊ธฐ ์ƒํƒœ๋กœ ๋Œ์•„๊ฐ€๋Š”๊ฑธ ๋ณด์žฅ์„ ๋ชปํ•˜๊ณ 

dead lock ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š” (์ง์ „) ์ƒํƒœ

 

 

์ตœ๋Œ€์น˜๋กœ ์‚ฌ์šฉํ•˜๋Š”๊ฑธ ๋น„๊ถŒ์žฅํ•˜๋Š” ์ด์œ  : ์—ฌ๋Ÿฌ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋™์ž‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ œ ๋•Œ release ํ•˜๋ฉด ๋‹คํ–‰์ด์ง€๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ  deadlock์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ๋ณด์ˆ˜์ ์œผ๋กœ ์•ˆ์ „ํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”๊ฑธ ๋ณด์žฅํ•œ๋‹ค.

 

๋Œ€ํ‘œ์ ์ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ Banker Algorithm์ด ์žˆ๋‹ค.

๋Œ€์ถœ ์‹œ์Šคํ…œ๊ณผ ๋น„์Šทํ•œ๋ฐ ๊ณ ๊ฐ๋งˆ๋‹ค ๋Œ€์ถœ ํ•œ๋„๊ฐ€ ๋‹ค๋ฅด๊ณ  ๋ฐ˜๋‚ฉํ•ด์•ผ ํ•˜๋Š”๊ฒŒ ๋น„์Šทํ•ด์„œ ์ด ๊ฐœ๋…์„ ์ ์šฉํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค. ์ด๋Š” ์‹œ๋ฎฌ๋ ˆ์ด์…˜์ด๋‹ค.

 

ํ•„์š”ํ•œ ์กฐ๊ฑด 3๊ฐ€์ง€

maxc[i,j] : ์ตœ๋Œ€ ์š”์ฒญ๊ฐ€๋Šฅํ•œ ๋ฆฌ์†Œ์Šค ๊ฐœ์ˆ˜์ด๋‹ค. Maximun Claim

alloc[i,j] : ํ˜„ ์ƒํƒœ์—์„œ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๊ฐ€์ง„ ๋ฆฌ์†Œ์Šค ๊ฐœ์ˆ˜์ด๋‹ค. :Allocated Resources 

C : ํ• ๋‹น ์ž์›์˜ ํ•ฉ

avail[j] ๊ณ„์‚ฐ ๊ฐ’์„ ํ†ตํ•ด safe์ธ์ง€ unsafe์ธ์ง€ ํ™•์ธํ•œ๋‹ค.

 

ํ˜„ ์‹œ์ ์—์„œ ๊ฐ๊ฐ ํ”„๋กœ์„ธ์Šค์—๊ฒŒ ๋ช‡๊ฐœ์”ฉ ํ• ๋‹น ๋˜์–ด์žˆ๋Š”์ง€ copyํ•œ๋‹ค.

์ง€๊ธˆ ๋ฆฌ์†Œ์Šค์˜ ์ตœ๋Œ€ ์ด์šฉ๋Ÿ‰์„ ์ด์šฉํ•˜์—ฌ avail์„ ๊ณ„์‚ฐํ•œ๋‹ค. (์ผ์ข…์˜ ์—ฌ์œ ๋ถ„)

์ด ์กฐ๊ฑด์— ๋งŒ์กฑํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋ฅผ ์ฐพ๋Š”๋‹ค.

๋‚จ์•„์žˆ๋Š” avail ๋ณด๋‹ค ํฐ ์กฐ๊ฑด์„ ์š”๊ตฌํ•˜๋ฉด unsafe

๋ชจ๋“  process๊ฐ€ ๋‹ค 0์ด๋˜๋ฉด safe ์ƒํƒœ์ด๋‹ค.

 

 

ํ”„๋กœ์„ธ์Šค p0๋ฅผ ๋ณผ ๋•Œ R0์˜ ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋ณด๋ฉด ์ตœ๋Œ€ 3๊ฐœ๋ฅผ ์š”์ฒญํ•  ์ˆ˜ ์žˆ์œผ๋‚˜ ํ˜„์žฌ 2๊ฐœ(allocated)๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ 1๊ฐœ๋งŒ ๋” ํ• ๋‹น ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

 

total allocated ๊ฐ’์„ ๊ตฌํ•˜์—ฌ

C - total alloc = avail ๊ฐ’์„ ๊ตฌํ•œ๋‹ค.

 

maxc - alloc ์ด avail๊ฐ’(์ตœ๋Œ€์น˜๊นŒ์ง€ ๋‹ค ์“ด๊ฒฝ์šฐ)๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ๋™์ž‘๊ฐ€๋Šฅํ•œ ์•ˆ์ „ํ•œ ์ƒํƒœ์ด๋‹ค.

 

์ž์›์„ ํ•ด์ œํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๊ณ  ์ž์› ํšŒ์ˆ˜๋ฅผ ํ•œ๋‹ค. avail + alloc

 

 

avail ์ƒํƒœ๊ฐ€ ๋ฐ”๋€ ์ดํ›„๋ฅผ ๋ณธ๋‹ค๋ฉด ์‹œ์Šคํ…œ์˜ ์ž์›์ด 5225๋กœ ์ฆ๊ฐ€ํ•˜์˜€๋‹ค.

 

์ตœ๋Œ€๋กœ ๋” ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ๊ฐ€ 2003 ์œผ๋กœ avail๋ณด๋‹ค ์ž‘์•„ safe์ƒํƒœ์ธ์ง€ ํ™•์ธํ•œ๋‹ค.

 

์‚ฌ์šฉํ•˜๊ณ  ํ• ๋‹น ํ•ด์ฒดํ•œ๋‹ค.

5225 + 1030 = 6255

 

 

 

unsafe ๋กœ ์ž˜๋ชป ํ•„๊ธฐ ํ•˜์˜€๋‹ค.

 

ํ• ๋‹น์„ ํ•ด์ œํ•ด์„œ ๊ฐ’์„ ๋Œ๋ ค์ฃผ๋ฉด C์— ๋‹ค์‹œ ๋”ํ•ด์ง€๋Š”๋ฐ ๋ชจ๋‘ ํ•ด์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋ฉด ๋‹ค์‹œ 8597๋กœ ๋Œ์•„๊ฐ„๋‹ค.

 

 

 

gray๋กœ ๋œ๊ฒƒ์€ ๋ฐ˜ํ™˜ํ•œ ์ƒํƒœ

 

 

 

 

 

Unsafe ์ƒํ™ฉ์„ ์•Œ์•„๋ณด์ž.

 

์ผ๋‹จ C์— allocated sum ์„ ๋บ€๋‹ค.

8597 - 8375 = 0222

 

๋‚ด๊ฐ€ ์š”๊ตฌํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€๋Ÿ‰์„ ์š”๊ตฌํ•ด๋ณธ๋‹ค.

P3 max-allo = 1530-1210

0320 < 0222

p3์˜ ์ž์› R1 ์—์„œ unsafe ์ƒํ™ฉ์ด ๋ฐœ๊ฒฌ๋˜์—ˆ๋‹ค.

 

 

 

 

Deadlock Detection & Recovery : ๋ฐ๋“œ๋ฝ ๊ฐ์ง€์™€ ํšŒ๋ณต <-> avoidance ํ• ๋‹นx ํšŒํ”ผํ•˜๋Š”๋ฐ

 

check for deadlock , then recovery

can be far more aggressive with allcoation

no maximum claim, no safe/ unsafe states

 

Differentiate between

- Serially reusable resources : ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ž์›, ์†Œ๋น„ํ•˜๊ณ  ๋ฐ˜ํ™˜ํ•˜์—ฌ ๋‹ค์‹œ ์ฑ„์›Œ์ง€๋Š” ์ž์›

- consumable resources : ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๊ณ  ์‚ฌ์šฉ ํ›„ ์—†์–ด์ง€๋Š” ์ž์›. ์ƒ์‚ฐ์ž์™€ ์†Œ๋น„์ž๊ฐ€ ์žˆ๋‹ค.

์ด๋Š” ํŒŒ์ผํฌ์ธํ„ฐ, ๋ฌธ์ž์ž…๋ ฅ, ๋งˆ์šฐ์Šค ํด๋ฆญ ,์ด๋ฒคํŠธ ์‹œ๊ทธ๋„ : ๋ชจ๋‘ ๋ฆฌ์†Œ์Šค์ด๋‹ค.

 

 

Reusable Resoucre Graph RRG : Micro model, C๊ฐ€ ์ด ํ•ฉ์ด๋‹ค. ์™„์ „ ์†Œ๊ฑฐ

Micro model : ํ•˜๋‚˜์˜ single state๋ฅผ ์กฐ๊ธˆ ๋” ์ž์„ธํ•˜๊ฒŒ ์„ค๋ช…ํ•œ๋‹ค.

Nodes ๊ฐ€ ๋‘๊ฐ€์ง€๊ฐ€ ์žˆ๋Š”๋ฐ p(o), R(ใ…) ์ด๋‹ค.

p,R ์ธ ๊ฒฝ์šฐ request edge : ์š”์ฒญ ์ƒํ™ฉ

R,p ์ธ ๊ฒฝ์šฐ assighment edge : ํ• ๋‹น ์ƒํ™ฉ

ํ™”์‚ดํ‘œ๋ฅผ ํ•ด์ œํ•˜๋ฉด ์ž์›์„ ๋ฐ˜๋‚ฉํ•œ ๊ฒƒ์ด๋‹ค.

 

 

 

 

 

์ƒํƒœ ๋ณ€ํ™”(์ „์ด)๊ฐ€ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

 

 

 

 

reusable resource๋ฅผ ์ƒํƒœ์ „์ด๊ทธ๋ž˜ํ”„๋กœ ๋ณธ ๊ฒฝ์šฐ์ด๋‹ค.

 

 

 

 

 

 

 

 

 

Graph Reduction ๊ทธ๋ž˜ํ”„์ถ•์†Œ : ์ œ๊ฑฐ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉด deadlock์ด๋‹ค. ๋ชจ๋‘ ์ œ๊ฑฐํ•˜๋ฉด ์•„๋‹ˆ๋‹ค.

Deaklock state if there is no sequence of transitions unblocking every process

๋ชจ๋“  ํ”„๋กœ์„ธ์Šค๋ฅผ unblockํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์œผ๋ฉด ๊ดœ์ฐฎ์ง€๋งŒ,

A RRG represents a state; can analyze the RRG to determine if there is a sequence 

 

์ œ๊ฑฐ : ๊ทธ ํ–‰๋™์ด ์ผ์–ด๋‚œ ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•˜๊ณ  ์‚ญ์ œ

 

์ œ๊ฑฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ

- block ์ƒํƒœ๊ฐ€ ์•„๋‹ˆ๋‹ค. (๋‹ค์Œ ์ƒํƒœ์ „์ด๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.)

- request edges ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๊ณ  assign edge๋Š” ์žˆ์„ ๋•Œ

 

 

RRG ๊ทธ๋ž˜ํ”„ ์ถ•์†Œ ๋ฐฉ๋ฒ• ์ •๋ฆฌ

 

1. ์ผ๋‹จ process ๋ฅผ ์ฐพ๋Š”๋‹ค.

2. ์š”์ฒญ์ค‘์ธ์ง€ ํ™•์ธํ•œ๋‹ค.

2.1. ์š”์ฒญ์ด ๊ฐ€๋Šฅํ•˜๋ฉด ์—†์•ค๋‹ค.

2.2. ์š”์ฒญ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉด ํ˜„์žฌ block์ด๋‹ค.

 

 

๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ฐพ๊ณ  ๊ณ„์† ์ง„ํ–‰ํ•ด์„œ ์„ ์ด ๋‚จ์•„์žˆ์œผ๋ฉด deadlock์ด๋‹ค.

 

 

 

Consumable Resource Graph (CRGs)

consumable resource ๊ฐ™์€ ๊ฒฝ์šฐ

p,R request egde : ์š”์ฒญ ์ƒํ™ฉ

R,p producer edge : ์ƒ์‚ฐ ์ƒํ™ฉ , ๋งŒ๋“ค์–ด๋‚ด๊ณ  ์„ ์„ ์ง€์›Œ๋ฒ„๋ฆฐ๋‹ค.

๋”ฐ๋ผ์„œ producer๊ฐ€ ์‚ด์•„์žˆ์œผ๋ฉด ์–ผ๋งˆ๋“ ์ง€ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ ์ด ์žˆ์–ด๋„ producer๊ฐ€ ์‚ด์•„์žˆ์œผ๋ฉด deadlock ์ด ์•„๋‹ˆ๋‹ค

 

 

 

 

 

 

 

 

๋”ฐ๋ผ์„œ ์œ„๋Š” ์•„๋ž˜์— ์„ ์ด ๋‚จ์•„ ์žˆ์–ด๋„ deadlock ์ด ์•„๋‹ˆ๋‹ค. (P1๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์‹ถ์ง€๋งŒ R0์— ๋ฆฌ์†Œ์Šค๊ฐ€ ์—†์–ด์„œ ์ œ๊ฑฐ๊ฐ€ ์•ˆ๋จ) ๊ทธ๋ ‡์ง€๋งŒ ์›ํ˜•์˜ ๋ชจ์–‘์ด๋ผ ์ด๊ฒŒ ์™œ deadlcok์ด ์•„๋‹Œ์ง„ ๋ชจ๋ฅด๊ฒ ๋‹ค. ํ•˜๋‚˜๋ผ๋„ producer ๊ฐ€ ์‚ด์•„์žˆ์œผ๋ฉด ๋˜๋Š”๊ฑด์ง€ ์‹ถ๋‹ค. ๋ฐ๋“œ๋ฝ์˜ ๊ธฐ์ค€์ด ๋‹ค๋ฅด๋‹ค๊ณ  ํ•˜๋Š”๋ฐ ์ƒ์‚ฐ์ž์ฒด๋งŒ ๋˜๋ฉด -> ์ผ๋‹จ ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”๋˜๋‹ˆ๊นŒ ์ •์ง€๋œ ์ƒํƒœ๋Š” ์•„๋‹ˆ๋‹ค?? ๋กœ ์ดํ•ดํ–ˆ๋‹ค. 

 

General Resource Graph : ์ผ๋ฐ˜์ ์ธ ๋ฆฌ์†Œ์Šค ๊ทธ๋ž˜ํ”„

 

 

reusable : ์™„์ „์†Œ๊ฑฐ

consumable : unblock

 

 

 

 

 

 

 

 

 

Recovery : ๋ณต๊ตฌ (ํšŒ๋ณต)

No magic here

-choose a blocked resource

- preempt it (releasing its resources) / ์„ ์ ํ•˜์—ฌ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ฆฌ์†Œ์Šค๋ฅผ ๋ฐ˜ํ™˜

- Run the detection algorithm

- Iterate if until the state is not a deadlock state

 

checkpoint / rollback (์‹œ์Šคํ…œ ๋ฆฌ๋ถ€ํŒ…์‹œ ์–ด๋–ป๊ฒŒ ๊ธฐ์–ต์„ ํ•˜๋Š” ๊ฑธ๊นŒ? -> ํ˜„์žฌ running state๋ฅผ ์ €์žฅ)

- Process periodically saves (checkpoints) the current running state.

- If the OS determines that there is a deadlock, the OS removes the process -> Another process uses the resource.

- After then, restart by resetting the process state based on checkpoint info.

์ด์ „ ๋™์ž‘์œผ๋กœ ๋ฆฌ๋ถ€ํŠธ