CS

๊ต์ฐฉ์ƒํƒœ

sun_young 2024. 11. 16. 14:27
๐Ÿ”Ž ๊ต์ฐฉ์ƒํƒœ
๋ณต์ˆ˜์˜ ํŠธ๋žœ์žญ์…˜์„ ์‚ฌ์šฉํ•˜๋‹ค ๋ณด๋ฉด ๊ต์ฐฉ์ƒํƒœ๊ฐ€ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋‹ค. 
๊ต์ฐฉ์ƒํƒœ๋ž€ ๋‘ ๊ฐœ ์ด์ƒ์˜ ํŠธ๋žœ์žญ์…˜์ด ํŠน์ • ์ž์›(ํ…Œ์ด๋ธ” ๋˜๋Š” ํ–‰)์˜ ์ž ๊ธˆ์„ ํš๋“ํ•œ ์ฑ„ ๋‹ค๋ฅธ ํŠธ๋žœ์žญ์…˜์ด ์†Œ์œ ํ•˜๊ณ  ์žˆ๋Š” ์ž ๊ธˆ์„ ์š”๊ตฌํ•˜๋ฉด ์•„๋ฌด๋ฆฌ ๊ธฐ๋‹ค๋ ค๋„ ์ƒํ™ฉ์ด ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ์ƒํƒœ๊ฐ€ ๋˜๋Š”๋ฐ, ์ด๋ฅผ ๊ต์ฐฉ์ƒํƒœ๋ผ๊ณ  ํ•œ๋‹ค.

 

์ถœ์ฒ˜ : https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/main/Database#%EA%B5%90%EC%B0%A9%EC%83%81%ED%83%9C

 

ํŠธ๋žœ์žญ์…˜ 1์ด ํ…Œ์ด๋ธ” B์˜ ์ฒซ๋ฒˆ์งธ ํ–‰์˜ ์ž ๊ธˆ์„ ์–ป๊ณ  ํŠธ๋žœ์žญ์…˜ 2๋„ ํ…Œ์ด๋ธ” A์˜ ์ฒซ๋ฒˆ์งธ ํ–‰์˜ ์ž ๊ธˆ์„ ์–ป์—ˆ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ,
ํŠธ๋žœ์žญ์…˜์„ COMMITํ•˜์ง€ ์•Š์€์ฑ„ ์„œ๋กœ์˜ ์ฒซ๋ฒˆ์งธ ํ–‰์— ๋Œ€ํ•œ ์ž ๊ธˆ์„ ์š”์ฒญํ•˜๋ฉด Deadlock์ด ๋ฐœ์ƒํ•œ๋‹ค.

 

๊ต์ฐฉ ์ƒํƒœ์˜ ๋นˆ๋„๋ฅผ ๋‚ฎ์ถ”๋Š” ๋ฐฉ๋ฒ•

  1. ํŠธ๋žœ์žญ์…˜์„ ์ž์ฃผ ์ปค๋ฐ‹ํ•œ๋‹ค.
  2. ์ •ํ•ด์ง„ ์ˆœ์„œ๋กœ ํ…Œ์ด๋ธ”์— ์ ‘๊ทผํ•œ๋‹ค.
    ์œ„์—์„œ๋Š” ํŠธ๋žœ์žญ์…˜ 1์ด ํ…Œ์ด๋ธ” B → A์˜ ์ˆœ์œผ๋กœ ์ ‘๊ทผํ–ˆ๊ณ , ํŠธ๋žœ์žญ์…˜ 2๋Š” ํ…Œ์ด๋ธ” A → B ์ˆœ์œผ๋กœ ์ ‘๊ทผํ–ˆ๋‹ค. 
    ํŠธ๋žœ์žญ์…˜๋“ค์ด ๋™์ผํ•œ ํ…Œ์ด๋ธ” ์ˆœ์œผ๋กœ ์ ‘๊ทผํ•˜๊ฒŒ ํ•œ๋‹ค.
  3. ์ฝ๊ธฐ ์ž ๊ธˆ ํš๋“ (SELECT ~ FRO UPDATE)์˜ ์‚ฌ์šฉ์„ ํ”ผํ•œ๋‹ค.
  4. ํ•œ ํ…Œ์ด๋ธ”์˜ ๋ณต์ˆ˜ ํ–‰์„ ๋ณต์ˆ˜์˜ ์—ฐ๊ฒฐ์—์„œ ์ˆœ์„œ ์—†์ด ๊ฐฑ์‹ ํ•˜๋ฉด ๊ต์ฐฉ์ƒํƒœ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ ์‰ฝ๋‹ค. ์ด ๊ฒฝ์šฐ์—๋Š” ํ…Œ์ด๋ธ” ๋‹จ์œ„์˜ ์ž ๊ธˆ์„ ํš๋“ํ•ด ๊ฐฑ์‹ ์„ ์ง๋ ฌํ™”ํ•˜๋ฉด ๋™์‹œ์„ฑ์€ ๋–จ์–ด์ง€์ง€๋งŒ ๊ต์ฐฉ์ƒํƒœ๋ฅผ ํšŒํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๊ต์ฐฉ ์ƒํƒœ ํƒ์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜

์€ํ–‰์› ์•Œ๊ณ ๋ฆฌ์ฆ˜

๊ฐ ์ž์› ์œ ํ˜•๋งˆ๋‹ค ์ธ์Šคํ„ด์Šค๊ฐ€ ์—ฌ๋Ÿฌ ๊ฐœ ์žˆ๋Š” ๊ฒฝ์šฐ ์€ํ–‰์› ์•Œ๊ณ ๋ฆฌ์ฆ˜(Banker's Algorithm)์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ต์ฐฉ ์ƒํƒœ๋ฅผ ํƒ์ง€ํ•œ๋‹ค.

 

  • ๊ฐ ํ”„๋กœ์„ธ์Šค์˜ ์ž์› ์š”์ฒญ(Request) ๊ฐœ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  • ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ž์›์„ ์š”๊ตฌํ•  ๋•Œ, ์‹œ์Šคํ…œ์€ ์ž์›์„ ํ• ๋‹นํ•œ ํ›„์—๋„ ํ˜„์žฌ ์ƒํƒœ๊ฐ€ ์•ˆ์ • ์ƒํƒœ์ธ์ง€ ํ™•์ธํ•œ๋‹ค.
  • ๋ถˆ์•ˆ์ • ์ƒํƒœ๋ผ๋ฉด ๊ต์ฐฉ ์ƒํƒœ๋ผ๊ณ  ํŒ๋‹จํ•œ๋‹ค.

โœ… ์•ˆ์ • ์ƒํƒœ๋ฉด ์ž์› ํ• ๋‹น, ์•„๋‹ˆ๋ฉด ๋‹ค๋ฅธ ํ”„๋กœ์„ธ์Šค๋“ค์˜ ์ž์› ํ•ด์ง€๊นŒ์ง€ ๋Œ€๊ธฐ

 

์ž์› ํ• ๋‹น ๊ทธ๋ž˜ํ”„ ์•Œ๊ณ ๋ฆฌ์ฆ˜

์ž์›๊ณผ ํ”„๋กœ์„ธ์Šค์— ๋Œ€ํ•ด ์š”์ฒญ ๊ฐ„์„ ๊ณผ ํ• ๋‹น ๊ฐ„์„ ์„ ์ ์šฉํ•˜์—ฌ ๊ต์ฐฉ ์ƒํƒœ๋ฅผ ํšŒํ”ผํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

 

  • ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ž์›์„ ์š”๊ตฌํ•  ๋•Œ ์š”์ฒญ ๊ฐ„์„ ์„ ํ• ๋‹น ๊ฐ„์„ ์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ์‚ฌ์ดํด์ด ์ƒ์„ฑ๋˜๋Š”์ง€ ํ™•์ธ

๐Ÿ“ข ์‚ฌ์ดํด์ด ์ƒ์„ ๋œ๋‹ค๊ณ  ๋ฌด์กฐ๊ฑด ๊ต์ฐฉ ์ƒํƒœ์ธ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค!

  1. ์ž์›์— ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋งŒ ์กด์žฌํ•˜๋ฉด ๊ต์ฐฉ ์ƒํƒœ๋กœ ํŒ๋ณ„
  2. ์ž์›์— ์—ฌ๋Ÿฌ ์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•˜๋ฉด ๊ต์ฐฉ ์ƒํƒœ ๊ฐ€๋Šฅ์„ฑ์œผ๋กœ ํŒ๋ณ„

ํƒ์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ˜ธ์ถœ ์ฃผ๊ธฐ

ํƒ์ง€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์–ผ๋งˆ๋‚˜ ์ž์ฃผ ๊ต์ฐฉ ์ƒํƒœ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”์ง€ ์–ผ๋งˆ๋‚˜ ๋งŽ์€ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๊ต์ฐฉ ์ƒํƒœ์— ์—ฐ๋ฃจ๋˜์–ด ์žˆ๋Š”์ง€์— ๋”ฐ๋ผ ํ˜ธ์ถœ ๋นˆ๋„๋ฅผ ์กฐ์ ˆํ•ด์•ผ ํ•œ๋‹ค.

  1.  ์ž์›์„ ์š”์ฒญํ–ˆ๋Š”๋ฐ ์ฆ‰์‹œ ํ• ๋‹น๋˜์ง€ ๋ชปํ•˜๋Š” ์‹œ์ ์— ํ˜ธ์ถœ
  2. ์ฃผ๊ธฐ์ ์œผ๋กœ ์ผ์ • ์‹œ๊ฐ„๋งˆ๋‹ค ํ˜ธ์ถœ
  3. cpu ์ด์šฉ๋ฅ ์ด ํŠน์ • ๊ฐ’ ์ดํ•˜๋กœ ๋–จ์–ด์ง€๋Š” ์‹œ์ ์— ํ˜ธ์ถœ

 

๋”๋ณด๊ธฐ

[์ฐธ๊ณ ]

https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/main/Database#%EA%B5%90%EC%B0%A9%EC%83%81%ED%83%9C

 

Interview_Question_for_Beginner/Database at main · JaeYeopHan/Interview_Question_for_Beginner

:boy: :girl: Technical-Interview guidelines written for those who started studying programming. I wish you all the best. :space_invader: - JaeYeopHan/Interview_Question_for_Beginner

github.com

 

https://github.com/gyoogle/tech-interview-for-developer/blob/master/Computer%20Science/Operating%20System/DeadLock.md

 

tech-interview-for-developer/Computer Science/Operating System/DeadLock.md at master · gyoogle/tech-interview-for-developer

๐Ÿ‘ถ๐Ÿป ์‹ ์ž… ๊ฐœ๋ฐœ์ž ์ „๊ณต ์ง€์‹ & ๊ธฐ์ˆ  ๋ฉด์ ‘ ๋ฐฑ๊ณผ์‚ฌ์ „ ๐Ÿ“–. Contribute to gyoogle/tech-interview-for-developer development by creating an account on GitHub.

github.com

 

https://yoongrammer.tistory.com/67

 

๊ต์ฐฉ์ƒํƒœ(Dead Lock) ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

๋ชฉ์ฐจ๊ต์ฐฉ์ƒํƒœ(Dead Lock) ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์ผ๋ฐ˜์ ์œผ๋กœ ๊ต์ฐฉ ์ƒํƒœ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์„ธ ๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.๊ต์ฐฉ ์ƒํƒœ ์˜ˆ๋ฐฉ(Prevention) ๋˜๋Š” ํšŒํ”ผ(Avoidance)๊ต์ฐฉ ์ƒํƒœ๊ฐ€ ๋˜์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.๊ต์ฐฉ ์ƒํƒœ ํƒ์ง€(Detec

yoongrammer.tistory.com