thread (ํน์ lightweight process)๋ CPU ์ํ๋จ์๋ก,
program counter
,register set
,stack space
๋ฅผ thread ๋ง๋ค ๋ณ๋๋ก ๊ฐ์ง๊ณ ์์ด์ผ ํ๋ค.
๊ทธ์ธ์ ๋ชจ๋ ๊ฒ์ ๊ณต์ ๊ฐ๋ฅํ๋ค.
thread ๊ฐ ๋๋ฃ thread ์ ๊ณต์ ํ๋ ๋ถ๋ถ (=task) ๋,
code section, data section, OS resources ๊ฐ ์๋ค.
์ ํต์ ์ธ ๊ฐ๋ ์ heavyweight process๋ ํ๋์ thread๋ฅผ ๊ฐ์ง๊ณ ์๋ task๋ก ๋ณผ ์ ์๋ค.
Single-threaded approach
Traditional approach of a single thread of execution per process has no concept of thread
ex) MS_DOS, old UNIX
Multi-threaded approach
Virtually all modern operating systems provide features enabling a process to contain multiple threads of control.
One process with multiple threads of execution
ex) Java run-time environment
Multiple processes with each of which supports multiple threads
ex) Windows, Solaris, modern UNIX
โ๏ธ Process vs. Threads
Process ๊ฐ ๋ฆฌ์์ค๋ฅผ ๊ฐ์ง๋ ์ฃผ์ฒด์ด๋, CPU ํ ๋น์ธ Scheduling ์ Thread ๋ณ๋ก ํด์ฃผ๊ฒ ๋ค.
- The unit of resource ownership is referred to as a process or task.
- Virtual address space (process image on memory)
- Protected access to processors, files, and I/O devices
- In OS that supports threads, the sheduling unit is usually referred to as a thread or lightweight process.
โ๏ธ Multi Threading
The ability of an OS to support multiple, concurrent paths(threads) of execution within a single process
- Process is the unit of resource allocation and protection
- Thread is the unit of dispatching with the following state
- Thread execution state (Ready, Run)
- Thread context : register values (PC, stack pointers)
- Thread execution stack (user stack, kernel stack)
All the threads of a process share the same address space and share the resources of that process
โ๏ธ ๋ค์ค ์ค๋ ๋๋ก ๊ตฌ์ฑ๋ ํ์คํฌ ๊ตฌ์กฐ์์๋ ํ๋์ ์๋ฒ ์ค๋ ๋๊ฐ blocked(waiting) ์ํ์ธ ๋์์๋ ๋์ผํ ํ์คํฌ ๋ด์ ๋ค๋ฅธ ์ค๋ ๋๊ฐ ์คํ(running)๋์ด ๋น ๋ฅธ ์ฒ๋ฆฌ๋ฅผ ํ ์ ์๋ค.
โ๏ธ ๋์ผํ ์ผ์ ์ํํ๋ ๋ค์ค ์ค๋ ๋๊ฐ ํ๋ ฅํ์ฌ ๋์ ์ฒ๋ฆฌ์จ (throughput)๊ณผ ์ฑ๋ฅ ํฅ์์ ์ป์ ์ ์๋ค.
โ๏ธ ์ค๋ ๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋ณ๋ ฌ์ฑ์ ๋์ผ ์ ์๋ค.
โ๏ธ ์๋ต์ฑ์ด ๋น ๋ฅด๋ค
โ๏ธ ์์ ๊ณต์ ๋ผ๋ ํจ์จ์ฑ
โ๏ธ creating & CPU switching thread (rather than a process) ๋ฉด์์ ๊ฒฝ์ ์ ์ด๋ค
โ๏ธ Benefits
โ๏ธ In OS with multithreading, scheduling and execution state is maintained at the thread-level, however some actions affect all the threads in the process.
Ready
, Run
, Blocked
Suspended
does not make sense since it is process-level state์ฐ๋ ๋๊ฐ ์๋ ์์ , ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ์ง์๋๋๋ก ํ๋ ๋ฒ์ ์ด๋ค. ์ค์ผ์ค๋ง ์ค์์นญ ๋ฑ๋ฑ ๋ชจ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก ์ง์ํ๋ค. ๋น ๋ฅด๊ณ ํจ์จ์ ์ด์ง๋ง, ์ฌ์ค ์ฑ๊ธ ํ๋ก์ธ์ค ์ฑ๊ธ CPU ๋ผ์ ๋ณ๋ ฌ ์ฒ๋ฆฌ๊ฐ ๋ถ๊ฐ๋ฅํ๋ค. U์์คํ ์ฝ์ด ์๊ธฐ๋ฉด ์ ์ฒด ํ๋ก์ธ์ค๊ฐ ๋ธ๋ก๋๋ค. ๊ทธ๋๋ ์ปค๋ ์ง์ ์ด ์์ด์ ๊ฐ๋ณ๊ณ , ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๊ฒ ์ค์ผ์ค๋ง ์๊ณ ๋ฆฌ์ฆ์ ์ต์ ํํด์ ๊ฐ๋ฐํ ์ ์๋ค๋ ์ด๋ฐ ์ฅ๋จ์ ์ด ์๋ค.
์ ์ ๋ ๋ฒจ์ ๊ณผ๋๊ธฐ๋ฅผ ๊ฑฐ์ณ์ OS๊ฐ ์ฐ๋ ๋๋ฅผ ์์ฑํด์ฃผ๊ธฐ ์์ํ๋ค. ๋ณ๋ ฌ ์ฒ๋ฆฌ๋ ๊ฐ๋ฅํ ๋ฉํฐ์ค๋ ๋์ด๋ค! ๋จ์ ์ด ์๋ค๋ฉด ์ค์์นญ ์ค๋ฒํค๋, ์๋๊ฐ ๋์์ง๋ค๋ ๊ฒ์ด๋ค. (์ค๋ฒํค๋๊ฐ ์ ์ ๋ ๋ฒจ์ 10๋ฐฐ ์ด์์ด๋ค.)
๊ทธ๋์ ์ ์ผ ์ข์ ๊ฒ์? ๋์ ์ฅ์ ์ ๋ชจ๋ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค!
Thread creation is done completely in the user space.
Multiple threads within the same process can run in parallel on multiple processors ๐ A blocking system call need not block the entire process
๋ค์ ๊ทธ๋ฆผ์ ๋ฉํฐ์ค๋ ๋ ํ๊ฒฝ์์ ์ค๋ ๋ ์ฌ์ด์ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๊ณต์ ๋๋ ๊ฒ์ ๋ํ๋ธ๋ค.
[KUOCW] ๋ฐํจ๊ฒฝ ๊ต์๋, ์ต๋ฆฐ ๊ต์๋์ ์ด์์ฒด์ ๊ฐ์๋ฅผ ์๊ฐํ๊ณ ์ ๋ฆฌํ ๋ด์ฉ์ ๋๋ค. ์๋ชป๋ ๋ด์ฉ์ด ์๋ค๋ฉด ๋๊ธ๋ก ์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค ๐