Multi Thread

Icarus_wยท2022๋…„ 12์›” 22์ผ
0

CS๊ณต๋ถ€

๋ชฉ๋ก ๋ณด๊ธฐ
4/25

thread๋Š” ํ•œ process ๋‚ด์—์„œ ์‹คํ–‰๋˜๋Š” ๋™์ž‘์˜ ๋‹จ์œ„๋ฅผ ๋งํ•œ๋‹ค.

MultiThread๋Š” ํ•˜๋‚˜์˜ process๊ฐ€ ๋™์‹œ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ผ์„ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ฃผ๋Š” ๊ฒƒ

ํ•œ process๋‚ด์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ thread ๊ฐ€ ์žˆ๊ณ , ๊ฐ thread๋“ค์€ Stack๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€(Code, Data, Heap) ์˜์—ญ์„ ๊ณต์œ ํ•˜๊ฒŒ ๋œ๋‹ค.

thread๋Š” process๋‚ด์—์„œ ๋…๋ฆฝ์ ์ธ ๊ธฐ๋Šฅ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. ์ฆ‰, ๋…๋ฆฝ์ ์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•จ์„ ์˜๋ฏธํ•˜๊ณ  ์ด๋ฅผ ์œ„ํ•ด ๋…๋ฆฝ์ ์ธ stack memory์™€ PC Register๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

(thread๋ผ๋ฆฌ๋„ context switch๊ฐ€ ์ผ์–ด๋‚˜๊ฒŒ ๋˜๋Š”๋ฐ, PC register์— code address๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ์–ด์•ผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ)
image
Q. thread๋Š” ์™œ ๋…๋ฆฝ์ ์ธ stack memory ์˜์—ญ์ด ํ•„์š”ํ• ๊นŒ?

stack์˜์—ญ์€ ํ•จ์ˆ˜ ํ˜ธ์ถœ ์‹œ ์ „๋‹ฌ๋˜๋Š” ์ธ์ž, ํ•จ์ˆ˜์˜ Return Address, ํ•จ์ˆ˜ ๋‚ด ์ง€์—ญ๋ณ€์ˆ˜ ๋“ฑ์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•œ memory์˜์—ญ์ด๋‹ค. thread๊ฐ€ process๋‚ด์—์„œ "๋…๋ฆฝ์ ์ธ ๊ธฐ๋Šฅ์„ ์‹คํ–‰"ํ•œ ๋‹ค๋Š” ๊ฒƒ์€ "๋…๋ฆฝ์ ์œผ๋กœ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ"ํ•จ์„ ์˜๋ฏธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ thread๊ฐ€ ๋…๋ฆฝ์ ์ธ ๋™์ž‘์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ thread์˜ stack memory ์˜์—ญ์ด ๋…๋ฆฝ์ ์ด์—ฌ์•ผ ํ•œ๋‹ค.

Q.process์™€ thread ๋น„๊ต

process๋Š” OS๋กœ ๋ถ€ํ„ฐ ์ž์›์„ ํ• ๋‹น๋ฐ›๋Š” ์ž‘์—…์˜ ๋‹จ์œ„

thread๋Š” process๊ฐ€ ํ• ๋‹น๋ฐ›์€ ์ž์›์„ ์ด์šฉํ•˜๋Š” ์‹คํ–‰์˜ ๋‹จ์œ„

process๋Š” memory๊ณต๊ฐ„์— code,data,heap,stack ์˜์—ญ์ด ์กด์žฌ

thread๋Š” process๋‚ด์—์„œ code,data,heap์˜์—ญ์„ ๊ณต์œ ํ•˜๊ณ  ๊ฐ๊ฐ์ด ๋…๋ฆฝ์ ์ธ stack์˜์—ญ์„ ๊ฐ€์ง

profile
ํ•˜๋ฃจ์— ํ•˜๋‚˜

0๊ฐœ์˜ ๋Œ“๊ธ€