Computer Science/๊ฐœ๋ฐœ์ž๋ผ๋ฉด ์•Œ์•„์•ผํ•˜๋Š” ๊ธฐ๋ณธ์ง€์‹

[์šด์˜์ฒด์ œ] Multiprocessing๊ณผ Multithreading์˜ ์ฐจ์ดโ€ผ๏ธ

_cactus 2022. 4. 1. 19:42
๋ฐ˜์‘ํ˜•

๐Ÿ“MultiProcessing

- ํ•˜๋‚˜์˜ ํ”„๋กœ๊ทธ๋žจ์„ ์—ฌ๋Ÿฌ๊ฐœ์˜ process๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ๊ฐ process๋งˆ๋‹ค ํ•˜๋‚˜์˜ ์ž‘์—…(task)์”ฉ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•˜๋Š” ๊ฒƒ

 

์˜ˆ์‹œ)

ํฌ๋กฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•ด๋ณด์ž. 

ํฌ๋กฌ ์ฐฝ์„ ์—ฌ๋Ÿฌ๊ฐœ ๋„์šด๋‹ค๊ณ  ํ•  ๋•Œ, ์ฒซ ๋ฒˆ์งธ ํฌ๋กฌ์ฐฝ์„ ์‹คํ–‰์‹œํ‚ค๋Š” process, ๋‘๋ฒˆ์งธ ํฌ๋กฌ์ฐฝ์„ ์‹คํ–‰์‹œํ‚ค๋Š” process, ์„ธ๋ฒˆ์งธ ํฌ๋กฌ์ฐฝ์„ ์‹คํ–‰์‹œํ‚ค๋Š” process ... 

 

์ด๋Ÿฐ์‹์œผ๋กœ ํฌ๋กฌ์ด๋ผ๋Š” ํ•˜๋‚˜์˜ ํ”„๋กœ๊ทธ๋žจ์—์„œ ์ผ์–ด๋‚˜๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ž‘์—…์„ process๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ์ƒ์„ฑํ•˜์—ฌ ํ•˜๋‚˜์”ฉ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•ด์ฃผ๋Š” ๊ฒƒ..!

 

 

์žฅ์ 

- ๋…๋ฆฝ๋œ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ์„ ๊ฐ์ž ํ• ๋‹น๋ฐ›๊ธฐ ๋•Œ๋ฌธ์— process๊ฐ„ ์„œ๋กœ์˜ ์ž์›์— ์นจํˆฌํ•  ์ˆ˜ ์—†์Œ → ์•ˆ์ •์„ฑ์ด ๋†’์Œ

๋‹จ์ 

- ์ž‘์—…๋Ÿ‰์ด ๋งŽ์•„์ง€๋ฉด *context switching์—์„œ์˜ ์˜ค๋ฒ„ํ—ค๋“œ ๋ฐœ์ƒ ๊ฐ€๋Šฅ
  (process๋“ค์ด ๋น ๋ฅด๊ฒŒ ์™”๋‹ค ๊ฐ”๋‹ค ํ•˜๋Š” ๊ณผ์ •์—์„œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์™€ ์‹œ๊ฐ„์ด ๋งŽ์ด ๋“ฆ)

- process๊ฐ„ ์ž์› ๊ณต์œ ๊ฐ€ ์–ด๋ ต๋‹ค

 

 

*context switching : ํ•˜๋‚˜์˜ process๊ฐ€ cpu๋ฅผ ์‚ฌ์šฉ์ค‘์ธ ์ƒํƒœ์—์„œ ๋‹ค๋ฅธ process๊ฐ€ cpu๋ฅผ ์‚ฌ์šฉํ•˜๋„๋กํ•˜๊ธฐ ์œ„ํ•ด ์ด์ „์˜ process์ƒํƒœ๋ฅผ ๋ณด๊ด€ํ•˜๊ณ  ์ƒˆ๋กœ์šด process์˜ ์ƒํƒœ๋ฅผ ์ ์žฌํ•˜๋Š” ์ž‘์—… (์ด process state์ •๋ณด๋Š” Process Control Block์— ์ €์žฅ๋œ๋‹ค)

 

 

๋ฐ˜์‘ํ˜•

 

๐Ÿ“Multithreading

- ํ•˜๋‚˜์˜ ํ”„๋กœ๊ทธ๋žจ์„ ์—ฌ๋Ÿฌ๊ฐœ์˜ thread๋กœ ๊ตฌ์„ฑํ•˜์—ฌ ๊ฐ thread๋งˆ๋‹ค ํ•˜๋‚˜์˜ ์ž‘์—…(task)์”ฉ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•˜๋Š” ๊ฒƒ

 

์˜ˆ์‹œ)

1. ์›น ๋ธŒ๋ผ์šฐ์ €

  - ํ™”๋ฉด์„ ์ถœ๋ ฅํ•˜๋Š” thread + ๋ฐ์ดํ„ฐ๋ฅผ ์ฝ์–ด์˜ค๋Š” thread

 

2. ์›Œ๋“œ ํ”„๋กœ์„ธ์„œ

  - ํ™”๋ฉด์„ ์ถœ๋ ฅํ•˜๋Š” thread + ํ‚ค๋ณด๋“œ ์ž…๋ ฅ์„ ๋ฐ›๋Š” thread + ์ฒ ์ž/๋ฌธ๋ฒ•์„ ํ™•์ธํ•˜๋Š” thread

 

 

 

 

 

์žฅ์ 

- thread๊ฐ„ code, data, heap์˜์—ญ ๊ณต์œ  → context switching์ด ๋น ๋ฆ„

- process๋ฅผ ์ƒ์„ฑํ•ด์„œ ์ž์›์„ ํ• ๋‹นํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ฏ€๋กœ ์ƒ์„ฑ/์ข…๋ฃŒ ์‹œ๊ฐ„๋„ process๋ณด๋‹ค ๋น ๋ฆ„

- process๊ฐ„ ํ†ต์‹ ์€ ๊นŒ๋‹ค๋กญ์ง€๋งŒ thread๋“ค์€ ๋ฉ”๋ชจ๋ฆฌ ์˜์—ญ์„ ๊ณต์œ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ†ต์‹ ๋ฐฉ๋ฒ•์ด ํ›จ์”ฌ ๊ฐ„๋‹จ (stack์˜์—ญ ์ œ์™ธ)

๋‹จ์ 

- ์„ค๊ณ„๊ฐ€ ๊นŒ๋‹ค๋กญ๋‹ค stack์˜์—ญ๋งŒ ๋นผ๊ณ  ๊ณต์œ ๋ฅผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ž์›๊ณต์œ ์˜ ๋ฌธ์ œ๊ฐ€ ์ƒ๊น€(๋™๊ธฐํ™”๋ฌธ์ œ)
   ์˜ˆ: heap์˜์—ญ์˜ ์ž์›์„ A thread๊ฐ€ ์ ‘๊ทผํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ B๊ฐ€ ๊ฐ‘์ž๊ธฐ ์ ‘๊ทผํ•ด์„œ ์ˆ˜์ •ํ•˜๋Š” ๊ฒฝ์šฐ

- ๋…๋ฆฝ์ ์ด์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜์˜ thread๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธฐ๋ฉด ์ „์ฒด thread๊ฐ€ ์˜ํ–ฅ์„ ๋ฐ›์Œ

 

 

 

๐Ÿ“iOS์—์„œ์˜ multiprocess & multithreading

- ios์—์„œ๋Š” multithread๋ฅผ ์ง€์›ํ•œ๋‹ค!!!!
  -> swift์—์„œ thread๊ด€๋ จ ์ž‘์—…์€ GCD๋ฅผ ํ†ตํ•ด์„œ ์ฒ˜๋ฆฌ๋จ

- UI ๊ด€๋ จ ์ž‘์—…๋“ค์€ main thread์—์„œ ๊ตฌํ˜„๋˜์–ด์•ผ ํ•จ

 

 

 

 

 

 

 

process์™€ thread์˜ ์ฐจ์ด๋ฅผ ๋ชจ๋ฅด๊ฒ ๋‹ค๋ฉด??
๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡
 

[์šด์˜์ฒด์ œ] Process์™€ thread์˜ ์ฐจ์ด (program vs process vs thread)

๐Ÿ“Program - ์ฝ”๋“œ๋กœ ๋งŒ๋“ค์–ด์ง„ ์ง‘ํ•ฉ์ฒด - ์˜ˆ์‹œ) ํฌ๋กฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ•˜๋‚˜์˜ ํ”„๋กœ๊ทธ๋žจ์ด๋ผ ํ•  ์ˆ˜ ์žˆ์Œ ๐Ÿ“Process - ํ”„๋กœ๊ทธ๋žจ์„ ์‹คํ–‰์‹œํ‚ค๋ฉด ๊ทธ๊ฒŒ process๊ฐ€ ๋จ!! (์‹คํ–‰์ค‘์ธ ํ”„๋กœ๊ทธ๋žจ์ด๊ธฐ ๋•Œ๋ฌธ์— job, task๋ผ

mac-user-guide.tistory.com

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•