virtual-thread

#thread #virtual-thread

๋ฐฐ๊ฒฝ

  • ์ œํ•œ๋œ ๋ฉ”๋ชจ๋ฆฌ ํ™˜๊ฒฝ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” [[os/thread]] ์˜ ์ˆ˜๊ฐ€ ์ œํ•œ๋˜์–ด์žˆ์Œ.

  • ๋˜ํ•œ ํ•„์š”ํ•œ ์Šค๋ ˆ๋“œ ์ˆ˜๊ฐ€ ์ฆ๊ฐ€ํ•˜๋ฉด์„œ, [[context-switching]] ๋น„์šฉ๋„ ์ฆ๊ฐ€ํ•จ.

  • ์œ„์˜ 2๊ฐ€์ง€ ๋ฌธ์ œ์ ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋‚˜์˜จ ๊ฐœ๋…์ด [[virtual-thread]].

ํŠน์ง•

  • [[context-switching]] ๋น„์šฉ์ด ์ €๋ ดํ•˜๋‹ค

image
  • ์™œ?

    • platform thread ์œ„์—์„œ ์—ฌ๋Ÿฌ virtual thread ๊ฐ€ ๋ฒˆ๊ฑธ์•„๊ฐ€๋ฉด์„œ ์‹คํ–‰๋˜๋Š” ํ˜•ํƒœ

    • ๊ธฐ์กด ๋ฐฉ์‹๋ณด๋‹ค ์ ์œ ํ•˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์ด์ฆˆ๊ฐ€ ์ ๊ณ , ์ปค๋„ ์˜์—ญ์˜ ํ˜ธ์ถœ์ด ์ ์Œ

๊ตฌ์กฐ

image1
image
  • ์Šค์ผ€์ฅด๋Ÿฌ๊ฐ€ platform thread ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค.

  • platform thread ๋Š” virtual thread ์˜ ์ž‘์—… ๋ถ„๋ฐฐ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค

image2
  • virtual thread๋Š” carrierThread ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

    • carrierThread ๋Š” platform thread ์ด๋‹ค.

    • carrierThread ๋Š” workQueue๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

  • virtual thread ๋Š” scheduler ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

    • scheduler ๋Š” ForkJoinPool ์ด๋‹ค

    • scheduler ๋Š” carrierThread ์˜ poll ์ด๋‹ค

    • scheduler ๋Š” virtual thread ์˜ ์Šค์ผ€์ฅด๋ง์„ ๋‹ด๋‹นํ•œ๋‹ค

  • virtual thread ๋Š” runConfiguration ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

    • runConfiguration ์€ ์‹ค์ œ ์ž‘์—… ๋‚ด์šฉ(runnable) ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค

์ •๋ฆฌ

  • virtual thread ๋Š” ๊ธฐ์กด platform thread ๋ฅผ ๋Œ€์ฒดํ•˜๋Š” ๊ฒƒ์ด ๋ชฉ์ ์ด ์•„๋‹˜.

    • platform thread ์˜ ๊ธฐ๋‹ค๋ฆผ์— ๋Œ€ํ•œ ๊ฐœ์„ ์ด ๋ชฉ์ .

  • virtual thread ๋ฅผ ๋„์ž…ํ•œ๋‹ค๊ณ  ํ•ด์„œ, ๋ฌด์กฐ๊ฑด์ ์œผ๋กœ ์ฒ˜๋ฆฌ๋Ÿ‰์ด ๋†’์•„์ง€์ง„ ์•Š์Œ.

  • ๋ฆฌ์•กํ‹ฐ๋ธŒ ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ๋™์ผํ•˜๊ฒŒ '์ฒ˜๋ฆฌ๋Ÿ‰' ์€ ์ฆ๊ฐ€ํ•˜์ง€๋งŒ ๋” ๊ฐ€๋…์„ฑ์ด ์ข‹๊ณ , ๊ฐœ๋ฐœ์ž ์นœํ™”์ ์ธ ๋ฐฉ๋ฒ•์ด๋‹ค.

Reference

  • https://techblog.woowahan.com/15398/

  • https://tech.kakao.com/2023/12/22/techmeet-virtualthread/

Last updated

Was this helpful?