Thread
ํ๋ก์ธ์ค ์ค์์ CPU ์ํ ๋จ์๋ฅผ ๋ํ๋ธ๋ค.
ํ๋ก์ธ์ค๊ฐ ๋ง๋ค์ด์ง๋ฉด ๊ฐ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์ ๊ณต๊ฐ์ด ์์ฑ๋๊ณ , ์ด์์ฒด์ ๊ฐ ์ด ํ๋ก์ธ์ค ํ๋๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด์ PCB๊ฐ ์์ฑ๋๋ค.
์ด๋ ๋์ผํ ํ๋ก์ธ์ค๊ฐ ๋์์ ํ ๋ ๊ฐ๊ฐ์ ํ๋ก์ธ์ค๋ฅผ ์์ฑํ์ฌ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ผ๊ฐ๋ฉด ๊ณต๊ฐ ๋ญ๋น๊ฐ ๋ ๊ฒ์ด๋ค. ์ด๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด Thread๋ฅผ ๋๋ค.
๋์ผํ ํ๋ก๊ทธ๋จ์ ์คํํ๋๋ผ๋ ํ๋์ ํ๋ก์ธ์ค๋ง ์์ฑ๋๋ค. ๊ฐ๊ฐ์ ํ๋ก๊ทธ๋จ์ ์๋ก ๋ค๋ฅธ ๋ถ๋ถ์ code๋ฅผ ์คํํ๊ฒ ๋๋๋ฐ, ํ๋ก์ธ์ค์์ CPU ์ํ๊ณผ ๊ด๋ จ๋ ๋ถ๋ถ๋ง ๋ณ๋๋ก ๊ด๋ฆฌํ๊ธฐ ์ํด Thread๋ฅผ ์ฌ์ฉํ๋ค.
๊ทธ ์ธ์ ๋ถ๋ถ๋ค์ ๋จ์ผ ํ๋ก์ธ์ค๋ก ๊ณต์ ํ๋ ๊ตฌ์กฐ๋ก ๋์ํ๋ค.
Thread์ ์ฅ์
- ํ ํ๋ก์ธ์ค์์ ๋ค๋ฅธ ํ๋ก์ธ์ค๋ก ๋์ด๊ฐ๋ ๋ฌธ๋งฅ ๊ตํ์ context๋ฅผ ์ ์ฅํ๊ณ ๋ณต์ํ๋ ๊ณผ์ ์ผ๋ก ์ธํด์ ์ค๋ฒํค๋๊ฐ ๋ง์ ์์ ์ด๋ค.
- → ๋์ผํ ํ๋ก์ธ์ค ์์์ ํ Thread์์ ๋ค๋ฅธ Thread์๊ฒ CPU๊ฐ ๋์ด๊ฐ๋ ๊ฒ์ ๋ฌธ๋งฅ ๊ตํ๊ณผ ๊ฐ์ ๊ฐ๋น์ผ ์ค๋ฒํค๋๊ฐ ํ์์๊ธฐ ๋๋ฌธ์ ํจ์จ์ ์ผ๋ก ์ํํ ์ ์๋ค.
- ๋์ผํ ์ผ์ ์ํํ๋ ๋ค์ค ์ค๋ ๋๊ฐ ํ๋ ฅํ์ฌ ๋์ ์ฒ๋ฆฌ์จ(throughtput)๊ณผ ์ฑ๋ฅ ํฅ์์ ์ป์ ์ ์๋ค. → ๊ณต์ ์์ ์ฌ์ฉ์ผ๋ก ๋ฉ๋ชจ๋ฆฌ ๋ญ๋น๋ฅผ ์ค์ผ ์ ์๋ค.
- ์ค๋ ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณ๋ ฌ์ฑ์ ๋์ผ ์ ์๋ค. → ์ฌ๋ฌ ๊ฐ์ ์ค๋ ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ๊ฐ์ CPU๋ฅผ ์ฌ์ฉํ ์ ์๊ณ , ์๋๊ฐ ๋นจ๋ผ์ง๋ค.
Benefits of Threads
Responsiveness (๋น ๋ฅธ ์๋ต์ฑ)
- ๋ค์ค Thread๋ก ๊ตฌ์ฑ๋ task ๊ตฌ์กฐ์์๋ ํ๋์ ์๋ฒ ์ค๋ ๋๊ฐ Blocked(waiting) ์ํ์ธ ๋์์๋ ๋์ผํ task ๋ด์ ๋ค๋ฅธ ์ค๋ ๋๊ฐ Running๋์ด ๋น ๋ฅธ ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค.
Resource Sharing (์์ ๊ณต์ )
- ๋์ ํ๋ก์ธ์ค ์์ ์๋ ์ค๋ ๋๋ค๋ผ๋ฆฌ๋ CPU ์ํ๊ณผ ๊ด๋ จ๋ ์ ๋ณด๋ฅผ ์ ์ธํ๊ณ ๋ ๋ชจ๋ ์์์ ๊ณต์ ํ๋ค.
Economy
- creating & CPU switching thread (rather than a process)
- Solaris์ ๊ฒฝ์ฐ ์ ๋ ๊ฐ์ง ์ค๋ฒํค๋๊ฐ ๊ฐ๊ฐ 30๋ฐฐ, 5๋ฐฐ
Utilization of MP Architectures
- ๋ฉํฐ ํ๋ก์ธ์ค ํ๊ฒฝ์์ ์ฌ๋ฌ ์ค๋ ๋๋ฅผ ํตํด ๋ณ๋ ฌ์ ์ผ๋ก ์์ ์ ์ํ์ํค๋ฉด ๋น ๋ฅธ ์ฐ์ฐ ์ํ์ด ๊ฐ๋ฅํ๋ค.
Thread์ ๊ตฌ์ฑ
์ค๋ ๋๋ CPU์ ์ํ ๋จ์์ด๊ธฐ ๋๋ฌธ์ Program Counter๋ register๋ฅผ ์ค๋ ๋๋ง๋ค ๋ณ๋๋ก ๊ฐ์ง๊ณ ์์ด์ผ ํ๋ค.
ํจ์ ํธ์ถ๊ณผ ๊ด๋ จ๋ ๋ฉ๋ชจ๋ฆฌ ์ฃผ์ ๊ณต๊ฐ์ stack ๋ถ๋ถ๋ง ๋ณ๋๋ก ๊ฐ์ง๊ณ ์๊ฒ ๋๋ค.
๊ทธ ์ธ ๋ชจ๋ ๊ฒ๋ค์ ๋์ผ ํ๋ก์ธ์ค ์์ ์๋ ์ค๋ ๋๋ผ๋ฆฌ ๊ณต์ ํ๋ค.
- Program Counter
- register set
- stack space
Thread๊ฐ ๋๋ฃ Thread์ ๊ณต์ ํ๋ ๋ถ๋ถ (stack)
- code section
- data section
- OS resource
Implementation of Threads (์ค๋ ๋์ ๊ตฌํ)
Kernel Threads
- Some ar supported by kernel
- ์ด์์ฒด์ ์ ์ปค๋์ด ์ง์ ์ง์ํด์ฃผ๋ ์ค๋ ๋๋ฅผ ์ฌ์ฉ
- ์ด์์ฒด์ ๊ฐ ์ค๋ ๋์ ์กด์ฌ๋ฅผ ์๊ณ ์๋ ์ํ์์ ๊ตฌํํ๋ ๊ฒ์ผ๋ก, ์๋ก ๋ค๋ฅธ ์ค๋ ๋๊ฐ ์ด์์ฒด์ ์๊ฒ๋ ์๋ก ๋ค๋ฅธ ํ๋ก์ธ์ค์ฒ๋ผ ๋ณด์ธ๋ค. ์ด์์ฒด์ ๊ฐ CPU ์ค์ผ์ค๋งํ ๋ ํ ํ๋ก์ธ์ค์์ ๋ค๋ฅธ ํ๋ก์ธ์ค๋ก CPU๋ฅผ ๋๊ธฐ๋ ์ํํ๋ ๊ฒ์ ์๋ฏธํ๋ค.
User Threads
- Others ar supported by library
- ์ฌ์ฉ์ ํ๋ก๊ทธ๋จ ๋จ์์ ์ค๋ ๋๋ฅผ ๊ด๋ฆฌ
- ๋ฉํฐ ์ค๋ ๋ ๊ธฐ๋ฐ์ ์ฌ์ฉ์ ํ๋ก๊ทธ๋จ์ ์ด์์ฒด์ ๊ฐ ๋ณด๊ธฐ์๋ ์ค๋ ๋๊ฐ ์๋ ํ๋ก์ธ์ค์ฒ๋ผ ๋ณด๊ธฐ ๋๋ฌธ์, ์ด๋ฐ ์ํฉ์์๋ ์ฌ์ฉ์ ํ๋ก๊ทธ๋จ์ธ ํ๋ก์ธ์ค์๊ฒ CPU๋ฅผ ๋๊ฒจ์ฃผ๊ฒ ๋๋ค.
- ์ค๋ ๋๊ฐ ๋น ๋ฅธ ์ฒ๋ฆฌ๊ฐ ๊ฐ๋ฅํ๋ฏ๋ก real-time๊ณผ ๊ด๋ จํ ์ค๋ ๋์ ์ฌ์ฉ๋๊ธฐ๋ ํ๋ค.
๊ฐ์ ์ถ์ฒ
http://www.kocw.net/home/search/kemView.do?kemId=1226304
์ด์์ฒด์
<๊ต์ฌ ๋ฐ ์ถ์ฒ><br/><br/>- A. Silberschatz et al., Operating System Concepts, 9th Edition, John Wiley & Sons, Inc. 2013.<br/><br/>- A. Silberschatz et al., Operating System Principles, Wiley Asia Student Edition<br/><br/>- ๋ฐํจ๊ฒฝ, ์ด์์ฒด์ ์
www.kocw.net