Thread

 

๐Ÿ’ก “A thread(or lightweight process) is a basic unit of CPU utilization”

 

  • Thread์˜ ๊ตฌ์„ฑ
    • Program Counter
    • Register Set
    • Stack Space

 

  • Thread๊ฐ€ ๋™๋ฃŒ Thread์™€ ๊ณต์œ ํ•˜๋Š” ๋ถ€๋ถ„***(=Task)***
    • Code Section
    • Data Section
    • OS Section

 

  • ์ „ํ†ต์ ์ธ ๊ฐœ๋…์˜ heavyweight process๋Š” ํ•˜๋‚˜์˜ thread๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” task๋กœ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

with Thread /  Program Counter์™€ ๋ ˆ์ง€์Šคํ„ฐ ๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋‘์–ด์„œ ์ฝ”๋“œ์˜ ์‹คํ–‰๋ถ€๋ถ„์„ ๋‚˜๋ˆ„๋Š” ๊ฒƒ์ž„ → ์Šคํƒ๋„ ๋ณ„๋„๋กœ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๊ณต๊ฐ„์„ ๊ณต์œ  / ํ”„๋กœ์„ธ์Šค ์ƒํƒœ๋„ ๊ณต์œ  / ํ”„๋กœ์„ธ์Šค๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ์ข… ์ž์›๋“ค๋„ ๊ณต์œ /  CPU์ˆ˜ํ–‰๊ณผ ๊ด€๋ จ๋œ ์ •๋ณด๋งŒ ๊ณต์œ ํ•˜์ง€ ์•Š์Œ!!!

 

  • ๋‹ค์ค‘ ์Šค๋ ˆ๋“œ๋กœ ๊ตฌ์„ฑ๋œ ํƒœ์Šคํฌ ๊ตฌ์กฐ์—์„œ๋Š” ํ•˜๋‚˜์˜ ์„œ๋ฒ„ ์Šค๋ ˆ๋“œ๊ฐ€ blocked(wating) ์ƒํƒœ์ธ ๋™์•ˆ์—๋„ ๋™์ผํ•œ ํƒœ์Šคํฌ ๋‚ด์˜ ๋‹ค๋ฅธ ์“ฐ๋ ˆ๋“œ๊ฐ€ ์‹คํ–‰(Running)๋˜์–ด ๋น ๋ฅธ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋‹ค.(=๋น„๋™๊ธฐ์ฒ˜๋ฆฌ?)
  • ๋™์ผํ•œ ์ผ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๋‹ค์ค‘ ์“ฐ๋ ˆ๋“œ๊ฐ€ ํ˜‘๋ ฅํ•˜์—ฌ ๋†’์€ ์ฒ˜๋ฆฌ์œจ(throughput)๊ณผ ์„ฑ๋Šฅ ํ–ฅ์ƒ์„ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.(์ฃผ์†Œ๊ณต๊ฐ„=๋ฉ”๋ชจ๋ฆฌ ๋ฅผ ๊ณต์œ ํ•˜๋ฏ€๋กœ ์ž์›์ ˆ์•ฝ์„ ํ•  ์ˆ˜ ์žˆ์–ด ํšจ์œจ์ด ์ข‹์Œ!)
  • ์“ฐ๋ ˆ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ณ‘๋ ฌ์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ๋‹ค.(CPU๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ๋‹ฌ๋ฆฐ ์ปดํ“จํ„ฐ์—์„œ๋งŒ ๊ฐ€๋Šฅ)

PCB์—์„œ์˜ ์“ฐ๋ ˆ๋“œ๊ฐ€ ๋ณ„๋„๋กœ ๊ฐ€์ง€๋Š” ์ •๋ณด
Single and Multithreaded Processes

 

์“ฐ๋ ˆ๋“œ์˜ ์žฅ์ 

 

1. Responsiveness

  • e.g. multi-threaded Web - if one thread is blocked (e.g. Network) another thread continues (e.g. 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

 

์“ฐ๋ ˆ๋“œ์˜ ๊ตฌํ˜„

  • ์ปค๋„ ์“ฐ๋ ˆ๋“œ๋Š” ์ปค๋„์ด ์“ฐ๋ ˆ๋“œ๋ฅผ ๊ด€๋ฆฌ(๋ช‡๊ฐœ ์žˆ๋Š”์ง€, ๋‹ค๋ฅธ ์“ฐ๋ ˆ๋“œ๋กœ ๋„˜๊ธฐ๋Š”๊ฒƒ๋„ ์ปค๋„์ด ๋„˜๊น€)
  • ์œ ์ € ์“ฐ๋ ˆ๋“œ์˜ ๊ฒฝ์šฐ๋Š” ์šด์˜์ฒด์ œ(์ปค๋„)๊ฐ€ ์“ฐ๋ ˆ๋“œ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์•Œ์ง€ ๋ชปํ•จ → ์ œ์•ฝ์ด ์žˆ์„ ์ˆ˜๊ฐ€ ์žˆ์Œ