CS/OS
๋ฐํจ๊ฒฝ [์ด์์ฒด์ ] 6๊ฐ, 7๊ฐ - Process 2
๋๊น
2023. 5. 14. 04:47
Thread
๐ก “A thread(or lightweight process) is a basic unit of CPU utilization”
- ์ฐ๋ ๋ - ํ๋ก์ธ์ค ํ๋์ CPU ์ํ ๋จ์๋ง ์ฌ๋ฌ ๊ฐ ๋๋ ๊ฒ
- Thread์ ๊ตฌ์ฑ(๊ฐ ์ฐ๋ ๋๋ง๋ค ๋ฐ๋ก ๊ฐ์ง๋ ๋ถ๋ถ)
- Program Counter
- Register Set
- Stack Space
- Thread๊ฐ ๋๋ฃ Thread์ ๊ณต์ ํ๋ ๋ถ๋ถ(=Task)
- Code Section
- Data Section
- OS Section
- ์ ํต์ ์ธ ๊ฐ๋ ์ heavyweight process๋ ํ๋์ thread๋ฅผ ๊ฐ์ง๊ณ ์๋ task๋ก ๋ณผ ์ ์๋ค.


์ฐ๋ ๋ ์ฌ์ฉ์ ์ฅ์
- ๋ค์ค ์ค๋ ๋๋ก ๊ตฌ์ฑ๋ ํ์คํฌ ๊ตฌ์กฐ์์๋ ํ๋์ ์๋ฒ ์ค๋ ๋๊ฐ blocked(wating) ์ํ์ธ ๋์์๋ ๋์ผํ ํ์คํฌ ๋ด์ ๋ค๋ฅธ ์ฐ๋ ๋๊ฐ ์คํ(Running)๋์ด ๋น ๋ฅธ ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค.
- ๋์ผํ ์ผ์ ์ํํ๋ ๋ค์ค ์ฐ๋ ๋๊ฐ ํ๋ ฅํ์ฌ ๋์ ์ฒ๋ฆฌ์จ(throughput)๊ณผ ์ฑ๋ฅ ํฅ์์ ์ป์ ์ ์๋ค.(์ฃผ์๊ณต๊ฐ=๋ฉ๋ชจ๋ฆฌ ๋ฅผ ๊ณต์ ํ๋ฏ๋ก ์์์ ์ฝ์ ํ ์ ์์ด ํจ์จ์ด ์ข์!)
- ์ฐ๋ ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณ๋ ฌ์ฑ์ ๋์ผ ์ ์๋ค.(MP์์)

Single and Multithreaded Processes

์ฐ๋ ๋์ ์ฅ์
1. Responsiveness(์๋ต์ฑ)
- eg) multi-threaded Web - if one thread is blocked (eg. Network) another thread continues (eg. Display) (๋น๋๊ธฐ์ ์ ์ถ๋ ฅ)
2. Resource Sharing(์์ ๊ณต์ )
- n threads can share binary code, data, resource of the process
3. Economy(๊ฒฝ์ ์ฑ)
- creating & CPU switching thread(rather than a process)
- Solaris์ ๊ฒฝ์ฐ ์ ๋๊ฐ์ง overhead๊ฐ ๊ฐ๊ฐ 30๋ฐฐ, 5๋ฐฐ(ํ๋ก์ธ์ค๋ฅผ ์์ฑํ๋ ๊ฒฝ์ฐ๊ฐ)
4. Utilization of MP Architectures(CPU๊ฐ ์ฌ๋ฌ๊ฐ ์๋ ํ๊ฒฝ์์๋ง)
MP = multi-processor
- each thread may be running in parallel on a different processor
์ฐ๋ ๋์ ๊ตฌํ
Some are supported by kernel ⇒ Kernel Threads
- ์ปค๋ ์ฐ๋ ๋๋ ์ปค๋์ด ์ฐ๋ ๋๋ฅผ ๊ด๋ฆฌ(๋ช๊ฐ ์๋์ง, ๋ค๋ฅธ ์ฐ๋ ๋๋ก ๋๊ธฐ๋๊ฒ๋ ์ปค๋์ด ๋๊น)
- Windows 95/98/NT
- Solaris
- Digital UNIX, Mach
Others are supported by library ⇒ User Threads
- ์ ์ ์ฐ๋ ๋์ ๊ฒฝ์ฐ๋ ์ด์์ฒด์ (์ปค๋)๊ฐ ์ฐ๋ ๋์ ๋ํ ์ ๋ณด๋ฅผ ์์ง ๋ชปํจ → ์ ์ฝ์ด ์์ ์๊ฐ ์์
- POSIX Pthreads
- Mach C-threads
- Solaris threads
Some are real-time threads
- ์ปค๋ ์ฐ๋ ๋๋ ์ปค๋์ด ์ง์ ์ฐ๋ ๋๋ฅผ ๊ด๋ฆฌ
- ์ ์ ์ฐ๋ ๋์ ๊ฒฝ์ฐ๋ ์ด์์ฒด์ ๊ฐ ์ฐ๋ ๋์ ๋ํ ์ ๋ณด๋ฅผ ์์ง ๋ชปํจ