E D R S I H C RSS
ID
Password
Join
์ž˜๋ชป์„ ์ €์ง€๋ฅด๊ณ ๋„ ํ›„ํšŒํ•  ์ค„ ๋ชจ๋ฅด๋Š” ์ž๋Š” ํ•˜๋“ฑ์˜ ์‚ฌ๋žŒ์ด์š”. ํ›„ํšŒํ•˜๋ฉด์„œ๋„ ๊ณ ์น  ์ค„ ๋ชจ๋ฅด๋Š” ์ž๋„ ํ•˜๋“ฑ์˜ ์‚ฌ๋žŒ์ด๋‹ค. -์†Œํ•™

๏ปฟ * ์›๋ฌธ๋งํฌ : [http]http://state-threads.sourceforge.net/docs/faq.html
  • ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋ฐ›์œผ๋ฉด docs ๋””๋ ‰ํ† ๋ฆฌ์— ๋“ค์–ด์žˆ์Šต๋‹ˆ๋‹ค.

Contents

1 State Threads library (ST)๊ฐ€ ๋ญ์ฃ ?
2 ST์™€ ์ „ํ†ต์ ์ธ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์ƒํƒœ๊ธฐ๊ณ„ ๊ตฌํ˜„๊ณผ ๋‹ค๋ฅธ ์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?
3 ST๊ฐ€ POSIX ์“ฐ๋ ˆ๋“œ์™€ ๋‹ค๋ฅธ ์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”?
4 ST์™€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋ ˆ๋ฒจ(user-level) ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(์˜ˆ๋ฅผ ๋“ค๋ฉด, GNU Pth)๋“ค๊ณผ์˜ ์ฐจ์ด์ ์€ ๋ญ์ฃ ?
5 ๋‹ค์ค‘ CPU์ƒ์—์„œ ST๋Š” ์–ด๋–ค ์ž‡์ ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‚˜์š”?
6 ST๋Š” ๋””์Šคํฌ ์ž…์ถœ๋ ฅ์„ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฃจ๋‚˜์š”?
7 ST์˜ ์ด์‹์„ฑ์€ ์–ด๋–ป์Šต๋‹ˆ๊นŒ?
8 ๋ฐฐํฌ๋˜๋Š” ST๋Š” ์–ด๋–ค ๋ผ์ด์„ผ์Šค๋ฅผ ์ ์šฉํ•˜๊ณ  ์žˆ๋‚˜์š”?
9 ST๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์žฅ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?
10 ST๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์žˆ์–ด ๋‹จ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

1 State Threads library (ST)๊ฐ€ ๋ญ์ฃ ? #

State Threads (ST)๋Š” ๋น ๋ฅด๊ณ  ๋งค์šฐ ํญ๋„“๊ฒŒ ํ™•์žฅ๊ฐ€๋Šฅํ•œ ๋„คํŠธ์›Œํฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ„ํ•œ ๊ธฐ์ดˆ๋ฅผ ์ œ๊ณตํ•˜๋Š” ์†Œ๊ทœ๋ชจ์˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ์“ฐ๋ ˆ๋“œ๋งˆ๋‹ค ๊ฐ๊ฐ ๋™์‹œ๋‹ค๋ฐœ์ ์ธ ์ ‘์†๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํŒจ๋Ÿฌ๋‹ค์ž„์˜ ๋‹จ์ˆœ์„ฑ์„, ์ด๋ฒคํŠธ๊ธฐ๋ฐ˜ ์ƒํƒœ๊ธฐ๊ณ„(event-driven state machine : EDSM) ๊ตฌ์กฐ๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํ™•์žฅ์„ฑ ๋ฐ ์„ฑ๋Šฅ๊ณผ ๊ฒฐํ•ฉํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๋น„๋ก ST๊ฐ€ ์ƒˆ๋กœ์šด "๋น„์•ฝ์ ์ธ" ์•„์ด๋””์–ด๋ฅผ ์†Œ๊ฐœํ•˜๊ณ  ์žˆ์ง€๋Š” ์•Š์ง€๋งŒ, ์ด๊ฒƒ์€ ๋งŽ์€ ๋„คํŠธ์›Œํฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์œ„ํ•œ ๋งค์šฐ ํšจ์œจ์ ์ธ ๊ธฐ์ˆ ์  ์†”๋ฃจ์…˜์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2 ST์™€ ์ „ํ†ต์ ์ธ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์ƒํƒœ๊ธฐ๊ณ„ ๊ตฌํ˜„๊ณผ ๋‹ค๋ฅธ ์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”? #

์ด๊ฒƒ์€ ์ค‘์š”ํ•œ ์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ST๋Š” ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ์–ด๋””์—์„œ๋ผ๋„ EDSM์„ ๋Œ€์ฒดํ•˜๋ ค๋Š” ๋ชฉ์ ์œผ๋กœ ๋””์ž์ธ ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

์ „ํ†ต์ ์ธ EDSM ๊ตฌํ˜„(๊ทธ๋ฆผ 1)์—์„œ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ํŠน์ • ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ๋งˆ๋‹ค (์˜ˆ๋ฅผ ๋“ค์–ด, ํ™”์ผ ๊ธฐ์ˆ ์ž(file descripter)๊ฐ€ ์ž…์ถœ๋ ฅ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๊ฐ€ ๋˜์—ˆ์„ ๋•Œ) ์‹คํ–‰๋  ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋“ค์„ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ๋ฉ”์ธ ๋””์ŠคํŒจ์นญ ๋ฃจํ”„๋Š” select(), poll() ๋˜๋Š” ์šด์˜์ฒด๊ณ„์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ๋‹ค๋ฅธ ์™ธ๋ถ€ ์žฅ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž…์ถœ๋ ฅ ๋˜๋Š” ํƒ€์ด๋ฐ ์ด๋ฒคํŠธ๋ฅผ ๋Œ€๊ธฐํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด, ๋””์ŠคํŒจ์ณ๋Š” ๊ทธ ์ด๋ฒคํŠธ์™€ ์—ฐ๊ด€๋œ ์•Œ๋งž์€ ์ฝœ๋ฐฑ("์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ")์„ ์‹คํ–‰์‹œํ‚ต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ „ํ†ต์ ์ธ EDSM ๊ตฌํ˜„์ƒ์—์„œ๋Š” ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ์œ„ํ•œ ๋กœ์ง์ด ์—ฌ๋Ÿฌ ์กฐ๊ฐ์œผ๋กœ ๋Š์–ด์ง„ ์ฝœ๋ฐฑ๋“ค์˜ ๋ฐฐ์—ด (์‚ฌ์Šฌ)๋กœ์„œ ํ‘œํ˜„๋ฉ๋‹ˆ๋‹ค. ์ฝœ๋ฐฑ์ด ๋ณต๊ท€ํ• ๋•Œ ์š”์ฒญ๊ณผ ์š”์ฒญ ์‚ฌ์ด์˜ ๋…ผ๋ฆฌ์ ์ธ "๋ฌธ๋งฅ ์ „ํ™˜(context switch)"์ด ์ผ์–ด๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ฝœ๋ฐฑ์ด ๋ณต๊ท€ํ•˜๊ธฐ ์ „์—, ์ผ๋ฐ˜์ ์œผ๋กœ ์š”์ฒญ์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ๋‹ค์‹œ ๊ณ„์†ํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ฒคํŠธ ๋„์ฐฉ์‹œ ์‹คํ–‰๋  ๋‹ค์Œ ์ฝœ๋ฐฑ์„ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋‹ค์Œ ์ฝœ๋ฐฑ์— ์ธ์ž๋กœ ๋„˜๊ธฐ๊ฒŒ ๋  ๋ฐ์ดํƒ€ ๊ตฌ์กฐ๋‚ด์— ์‹คํ–‰์ƒํƒœ๋ฅผ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.


์ „ํ†ต์ ์ธ EDSM์˜ ๊ทผ๋ณธ์ ์ธ ๋ฌธ์ œ๋Š” ๊ตฌํ˜„ ๋ฐ ํ™•์žฅํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๋‹ค๋ผ๋Š” ์ ์ž…๋‹ˆ๋‹ค. ์ด๊ฒƒ์„ ์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด์ฃผ๋Š” ๋ช‡๋ช‡ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ํ”„๋ ˆ์ž„์›Œํฌ(์†Œํ˜•์˜ [http]libevent์—์„œ ๋ณต์žกํ•œ [http]ACE reactor/proactor ํŒจํ„ด์— ์ด๋ฅด๊ธฐ๊นŒ์ง€ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค)๊ฐ€ ์žˆ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ , ๋ณธ์งˆ์ ์ธ "์ฝœ๋ฐฑ์„ ์ฑ„์›Œ์•ผํ•œ๋‹ค๋Š” ์„ ํ˜•์ ์ธ ์ƒ๊ฐ์„ ๊นจ๋ฒ„๋ ค์•ผํ•˜๋Š”๋ฐ์„œ ์ƒ๊ธฐ๋Š” ๋ณต์žกํ•จ"(Dean Gaudet์ด ์–ธ๊ธ‰ํ•œ ๋ง์ž…๋‹ˆ๋‹ค)์€ ๊ณ„์† ๋‚จ์•„์žˆ์Šต๋‹ˆ๋‹ค.

ST ๊ตฌํ˜„์€ ์•ž์„œ ์–ธ๊ธ‰ํ•œ EDSM ๋ชจ๋ธ์˜ ๋‚ด๋ถ€๋ฅผ ๋’ค์ง‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค(๊ทธ๋ฆผ 2). ์ด๊ฒƒ์€ ๋งŽ์€ ๋„คํŠธ์›Œํฌ ์„œ๋ฒ„์•ˆ์—์„œ ๋ฐœ๊ฒฌ๋˜๋Š” ์ „ํ†ต์ ์ธ EDSM์„ ๋Œ€์ฒดํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค.


ST๋Š” ์“ฐ๋ ˆ๋“œ ์ถ”์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ๋”ฐ๋ผ์„œ ์ž์—ฐ์Šค๋Ÿฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋ธ์„ ์œ ์ง€ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์ „ํ†ต์ ์ธ EDSM๋“ค๊ณผ๋Š” ๋‹ฌ๋ฆฌ ๋ฉ”์ธ ๋””์ŠคํŽ˜์น˜ ๋ฃจํ”„๊ฐ€ ๋ฐ–์œผ๋กœ ๊บผ๋‚ด์ ธ์žˆ๊ณ , ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜๋“ค์€ ์ด ๋ฃจํ”„ ์ฃผ์œ„์— ๊ตฌ์„ฑ๋˜์–ด์ ธ ์žˆ์œผ๋ฉฐ, ST ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋‚ด๋ถ€์— ์ˆจ๊ฒจ์ ธ ์žˆ์–ด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ž‘์„ฑ์ž์—๊ฒŒ๋Š” ๋ณด์ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์‹คํ–‰์ƒํƒœ๋Š” C ํ™˜๊ฒฝ์— ์˜ํ•ด ํˆฌ๋ช…ํ•˜๊ฒŒ ๊ด€๋ฆฌ๋˜๋Š” ์“ฐ๋ ˆ๋“œ๊ฐ€ ์†Œ์œ ํ•˜๊ณ  ์žˆ๋Š” ์Šคํƒ(๋ฉ”๋ชจ๋ฆฌ์˜ ์—ฐ์†์ ์ธ ๋ฉ์–ด๋ฆฌ)์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.

์“ฐ๋ ˆ๋“œ๊ฐ€ ํŠน์ • ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚ ๋•Œ๊นŒ์ง€ ๋Œ€๊ธฐํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๋•Œ๋งˆ๋‹ค, ์“ฐ๋ ˆ๋“œ๋Š” ์ž์‹ ์˜ ์‹คํ–‰์ƒํƒœ๋ฅผ ๋ณด๊ด€ํ•˜๊ณ  ์ž๊ธฐ์ž์‹ ์„ ์ด๋ฒคํŠธ ๋Œ€๊ธฐ ํ์— ๋„ฃ์Šต๋‹ˆ๋‹ค (์ด๊ฒƒ์€ ์ „ํ†ต์ ์ธ EDSM์—์„œ ์ฝœ๋ฐฑ์„ ๋“ฑ๋กํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ํšจ๊ณผ๋ฅผ ๊ฐ€์ง‘๋‹ˆ๋‹ค). ๊ทธ๋Ÿฌ๋ฉด ์Šค์ผ€์ค„๋Ÿฌ๊ฐ€ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์‹คํ–‰ ํ๋กœ๋ถ€ํ„ฐ ์ฒซ๋ฒˆ์งธ ์“ฐ๋ ˆ๋“œ๊ฐ€ ๊บผ๋‚ด์–ด์ง€๊ณ  ๊ทธ๊ฒƒ์˜ ์‹คํ–‰์ƒํƒœ๊ฐ€ ๋ณต๊ตฌ๋ฉ๋‹ˆ๋‹ค (์ด๊ฒƒ์€ ์ „ํ†ต์ ์ธ EDSM์—์„œ ์ฝœ๋ฐฑ์„ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์€ ํšจ๊ณผ์ž…๋‹ˆ๋‹ค). ๋งŒ์ผ ์‹คํ–‰๊ฐ€๋Šฅํ•œ ์“ฐ๋ ˆ๋“œ๊ฐ€ ์—†๋‹ค๋ฉด(์‹คํ–‰ ํ๊ฐ€ ๋น„์—ˆ๋‹ค๋ฉด), ์Šค์ผ€์ค„๋Ÿฌ๋Š” select(), poll() ๋˜๋Š” ๊ฐ€๋Šฅํ•˜๋‹ค๋ฉด ๊ทธ ์šด์˜์ฒด๊ณ„์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ๋‹ค๋ฅธ ์™ธ๋ถ€ ์žฅ์น˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž…์ถœ๋ ฅ ํ˜น์€ ํƒ€์ด๋ฐ ์ด๋ฒคํŠธ๋ฅผ ๋Œ€๊ธฐํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ๊ฐ€ ์ผ์–ด๋‚˜๋ฉด, ์Šค์ผ€์ค„๋Ÿฌ๋Š” ์‹คํ–‰ ํ์— ์“ฐ๋ ˆ๋“œ๋“ค์„ ๋„ฃ์Œ์œผ๋กœ์„œ ๊ฐ๊ฐ์˜ ์ด๋ฒคํŠธ๋ฅผ ๋Œ€๊ธฐํ•˜๊ณ  ์žˆ๋Š” ์“ฐ๋ ˆ๋“œ๋“ค์„ "๊นจ์šฐ๊ฒŒ" ๋ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์ฒ˜์Œ ์‹คํ–‰๊ฐ€๋Šฅํ•œ ์“ฐ๋ ˆ๋“œ์˜ ์‹คํ–‰์ƒํƒœ๊ฐ€ ๋ณต๊ตฌ๋ฉ๋‹ˆ๋‹ค. ์‹คํ–‰ ์‚ฌ์ดํด์€ ์™„๋ฒฝํ•ฉ๋‹ˆ๋‹ค.

์„ฑ๋Šฅ ์ธก๋ฉด์—์„œ ๋ณด๋ฉด ST๋Š” ์ „ํ†ต์ ์ธ EDSM ๊ตฌํ˜„๋งŒํผ ๋น ๋ฆ…๋‹ˆ๋‹ค. ๋ฌธ๋งฅ ์ „ํ™˜์— ์žˆ์–ด์„œ์˜ ๊ณผ๋ถ€ํ•˜๋Š” _setjmp()/_longjmp() ์˜ ๋น„์šฉ๋งŒ์ด ์†Œ๋ชจ๋ฉ๋‹ˆ๋‹ค(์–ด๋– ํ•œ ์‹œ์Šคํ…œ ํ˜ธ์ถœ๋„ ์‹คํ–‰ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค). ์ด๊ฒƒ์€ ๋ชจ๋“  ์‹ค์ œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ๋Š” ๋ฌด์‹œํ• ๋งŒํ•œ ์ •๋„์ž…๋‹ˆ๋‹ค. ์“ฐ๋ ˆ๋“œ ์ƒ์„ฑ ๊ณผ๋ถ€ํ•˜ ๋˜ํ•œ ๋งค์šฐ ์ž‘์Šต๋‹ˆ๋‹ค.

๋ฉ”๋ชจ๋ฆฌ ์ธก๋ฉด์—์„œ ๋ณด์•„๋„ ST๋Š” ๊ฑฐ์˜ ์ „ํ†ต์ ์ธ EDSM์™€ ๋งž๋จน๊ฒŒ ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. ์“ฐ๋ ˆ๋“œ๋ฅผ ์ƒ์„ฑํ• ๋•Œ ์ „์ฒด ์Šคํƒ ์„ธ๊ทธ๋จผํŠธ์— ๋Œ€ํ•ด swap ๊ณต๊ฐ„์ด ์˜ˆ์•ฝ๋˜์–ด์žˆ๋‹คํ•˜๋”๋ผ๋„, ๋‹จ์ง€ ์‹ค์ œ๋กœ ์‚ฌ์šฉ๋˜๋Š”(๊ฑด๋“œ๋ฆฌ๋Š”) ์Šคํƒ ํŽ˜์ด์ง€๋Š” ๋ฌผ๋ฆฌ์  ๋ฉ”๋ชจ๋ฆฌ์ƒ์— ๋†“์ด๊ฒŒ ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์–ด์จŒ๋“ , ์“ฐ๋ ˆ๋“œ์˜ ์ตœ์†Œ ๋ฉ”๋ชจ๋ฆฌ ์š”์ฒญ๋‹น 1 ํŽ˜์ด์ง€์”ฉ์€ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์–ด๋–ป๊ฒŒ ์ž‘์„ฑํ•˜๋”๋ผ๋„ (ST ๋˜๋Š” ์ „ํ†ต์  EDSM์ด๋“ ๊ฐ„์—) ์‹คํ–‰์ƒํƒœ๋Š” ์–ด๋”˜๊ฐ€์—๋Š” ์ €์žฅ๋˜์–ด์•ผ๋งŒ ํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์„ ์Šคํƒ์— ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์€ ํŠน์ • ๋ฐ์ดํƒ€ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค. ASF์˜ [http]Dean Gaudet์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ ์—ˆ์Šต๋‹ˆ๋‹ค:

... one of the arguments the event folks sometimes throw against the thread folks is that the thread folks have a stack per thread. And if you've got a thread per connection then you're paying a stack per connection. That can be expensive if your stack is really deep. Whereas with the event model you only have one stack.

It's a good point. The counterpoint is that in the event model, much of the state which the thread folks store on the stack is stored on the heap, in a different form. And because languages such as C are designed more for the threaded/linear programming model, there are few optimizations to help the event folks. For example, in thread land you'd write code:

       int foo()
       {
           int local1;
           int local2;
           ...
           do_some_io();
           ...
       }


in event land you might write:
       struct foo_data {
           int local1;
           int local2;
           ...
       };

       void foo_after_io_completes(void *arg)
       {
           struct foo_data *locals = arg;
           ...
       }

       void foo()
       {
           struct foo_data *locals = malloc(sizeof(struct foo_data));
           ...
           initiate_io(foo_after_io_completes, locals);
       }


But in the thread version, some of those locals may actually never be allocated. They may live only in registers. But the compiler can't perform that optimization in the event model. These sort of micro details are what make me question how good the event model really is for the average programmer who doesn't want to think about cycles all the time. That's what compilers are supposed to help with.

์ด๋ฉ”์ผ ์“ฐ๋ ˆ๋“œ ์ „๋ฌธ์„ ๋ณด๊ธฐ์œ„ํ•ด์„œ๋Š” [http]์•„ํŒŒ์น˜ ์„œ๋ฒ„ ๊ฐœ๋ฐœ ๋ฉ”์ผ๋ง ์•„์นด์ด๋ธŒ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์š”.

3 ST๊ฐ€ POSIX ์“ฐ๋ ˆ๋“œ์™€ ๋‹ค๋ฅธ ์ ์€ ๋ฌด์—‡์ธ๊ฐ€์š”? #

POSIX ๊ทœ์•ฝ (IEEE 1003.1c, ๋˜๋Š” Pthreads)์€ ์ด ๊ทœ์•ฝ์„ ๋”ฐ๋ฅด๋Š” ๋ชจ๋“  ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ๋‹ด๊ณ  ์žˆ์–ด์•ผ๋งŒ ํ•˜๋Š” API์™€ ๊ธฐ๋Šฅ์„ ์ •์˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฑฐ์˜ ๋ชจ๋“  UNIX๋“ค์€ Pthreads ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์„ ์ œ๊ณตํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ์ด๋“ค์ค‘ ๋งŽ์€ ์ˆ˜๊ฐ€ ์ด๊ฒƒ์„ ์ปค๋„์ƒ์—์„œ ์ง€์›ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค(์‚ฌ์šฉ์ž์ˆ˜์ค€ ์“ฐ๋ ˆ๋“œ๋“ค์„ ์ปค๋„ ๊ฐ์ฒด๋กœ ๋งคํ•‘ํ•˜๊ธฐ์œ„ํ•œ 1:1 ๋˜๋Š” n:m ๋ชจ๋ธ(๋‹ค์ˆ˜->๊ทน์†Œ์ˆ˜)์„ ์ง€์›ํ•˜๋Š” ๊ฒƒ์„ ๋งํ•ฉ๋‹ˆ๋‹ค)

Pthreads๋Š” ์ผ๋ฐ˜์ ์ธ ์šฉ๋„์˜ ์“ฐ๋ ˆ๋“œ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์‹œ๋งํ•˜๋ฉด, POSIX ๊ทœ์•ฝ์„ ๋งŒ์กฑํ•˜๋Š” ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๊ด‘๋ฒ”์œ„ํ•œ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ •ํ™•ํ•˜๊ฒŒ ๋™์ž‘ํ•˜์—ฌ์•ผ๋งŒ ํ•ฉ๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ๋งŽ์€ ๊ฒฝ์šฐ ์ด๊ฒƒ์€ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ๋„คํŠธ์›Œํฌ ์„œ๋ฒ„์™€ ๊ฐ™์€ ํŠน์ • ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์˜์—ญ์— ๋Œ€ํ•œ ์ตœ์„ ์˜ ์„ ํƒ์ด ๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. Pthreads์˜ ์œตํ†ต์„ฑ์€ ์ž๊ธฐ์ž์‹ ๋งŒ์˜ ๋‹จ์ ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋ช‡๋ช‡ ์ปค๋„ ์‹คํ–‰ ๊ฐ์ฒด("๊ฒฝ๋Ÿ‰ ํ”„๋กœ์„ธ์Šค(lightweight process)")๋กœ ํ•˜์—ฌ๊ธˆ ๊ฐ™์€ ์ฃผ์†Œ๊ณต๊ฐ„๊ณผ ๋‹ค๋ฅธ ์ž์›์„ ๊ณต์œ ํ•˜๋Š” ๊ฒƒ์„ ํ—ˆ๊ฐ€ํ•˜๋Š” ๊ฒƒ์€ ์ƒˆ๋กœ์šด ์ˆ˜์ค€์˜ ๋ณต์žกํ•จ์„ ๋‚ณ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. [http]Linux Threads FAQ์—์„œ ์ธ์šฉํ•˜์ž๋ฉด: "๊ณต์œ , ์ž ๊ธˆ, ๋ฐ๋“œ๋ฝ, ๊ฒฝ์Ÿ ์ƒํƒœ๋“ฑ๋“ฑ์— ๋Œ€ํ•œ ๋ชจ๋“  ์•…๋ชฝ์€ ์“ฐ๋ ˆ๋“œ์•ˆ์— ์ƒ์ƒํ•˜๊ฒŒ ์‚ด์•„์žˆ์Šต๋‹ˆ๋‹ค... ์“ฐ๋ ˆ๋“œ๋Š” ํ™”์ผ ํ•ธ๋“ค, ํŒŒ์ดํ”„, ๋ณ€์ˆ˜, ์‹œ๊ทธ๋„๋“ฑ๋“ฑ์˜ ๊ฒƒ๋“ค์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ค๋ฅ˜ ์ƒํƒœ๋“ค์„ ํ…Œ์ŠคํŠธํ•˜๊ฑฐ๋‚˜ ๋ณต์ œํ•˜๋ ค๋Š” ๊ฒƒ์€ ๋ง์•ˆ๋“ฃ๋Š” ์•„์ด๋“ค์„ ๋Œ๋ณด๋Š” ๊ฒƒ๋ณด๋‹ค ๋‹น์‹ ์˜ ๋จธ๋ฆฌ๋ฅผ ๋” ๋นจ๋ฆฌ ํ•˜์–—๊ฒŒ ์„ธ๋„๋ก ๋งŒ๋“ค ๊ฒƒ์ž…๋‹ˆ๋‹ค." ์ด์‹์„ฑ์„ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ, Pthreads๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ž‘์„ฑ์ž๋Š” Pthreads์˜ ๋‚ด์žฌ๋œ ๊ตฌํ˜„์— ๋Œ€ํ•œ ์–ด๋–ค ๊ณ ๋ ค๋„ ํ•˜์ง€ ๋ง์•„์•ผํ•˜๋ฉฐ, ์–ธ์ œ๋‚˜ ์ด๋“ค์ด ๋™์‹œ์ฒ˜๋ฆฌ์ ์ด๊ณ  ์„ ์ ์ ์ธ ๊ฒƒ์ฒ˜๋Ÿผ ๋‹ค๋ฃจ์–ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๋ฐ˜๋ฉด์—, ST๋Š” ์ผ๋ฐ˜์ ์ธ ์šฉ๋„์˜ ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์˜๋ฏธํ•˜์ง„ ์•Š์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ๋งŽ์€ ๋„คํŠธ์›Œํฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋ฐœ๊ฒฌ๋˜๋Š” ์ „ํ†ต์ ์ธ EDSM๋“ค์„ ๋Œ€์ฒดํ•  ๋ชฉ์ ์œผ๋กœ ๋””์ž์ธ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ST๋Š” ์™„์ „ํžˆ ๊ฒฐ์ •์— ์˜์กดํ•˜๋ฉฐ ์–ธ์ œ๋‚˜ ๋ฌธ๋งฅ์ „ํ™˜์ด ๋‹จ์ง€ ์ž˜ ์•Œ๋ ค์ง„ ํ•จ์ˆ˜๊ตฐ(์ž…์ถœ๋ ฅ ์‹œ์  ๋˜๋Š” ๋ช…์‹œ์ ์ธ ๋™๊ธฐํ™” ์‹œ์ )์—์„œ๋งŒ ๋ฐœ์ƒํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด์ฆํ•ฉ๋‹ˆ๋‹ค. ๊ฒฐ๋ก ๋งŒ ๋งํ•˜์ž๋ฉด, ์ „์—ญ ๋ฐ์ดํƒ€๋Š” ์ƒํ˜ธ ๋ฒ ํƒ€์  ์ž ๊ธˆ(๋ฎคํ…์Šค)๋กœ ๋ณดํ˜ธ๋  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์ „์ฒด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ž์œ ๋กญ๊ฒŒ ๋ชจ๋“  ์ •์  ๋ณ€์ˆ˜์™€ ์›ํ•˜๋Š” ์žฌ์ง„์ž…์š”์†Œ๊ฐ€ ์—†๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํ•จ์ˆ˜๋“ค์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์„ฑ๋Šฅํ–ฅ์ƒ๊ณผ ๋™์‹œ์— ํ”„๋กœ๊ทธ๋ž˜๋ฐ๊ณผ ๋””๋ฒ„๊น…์„ ์—„์ฒญ๋‚˜๊ฒŒ ๋‹จ์ˆœํ•˜๊ฒŒ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

์“ฐ๋ ˆ๋“œ์— ๋Œ€ํ•œ ๋ณด๋‹ค ์ผ๋ฐ˜์ ์ธ ์ •๋ณด๋ฅผ ์—ด๋žŒํ•˜๊ธธ ์›ํ•œ๋‹ค๋ฉด [http]comp.programming.threads FAQ ์ฐธ์กฐํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

4 ST์™€ ๋‹ค๋ฅธ ์‚ฌ์šฉ์ž๋ ˆ๋ฒจ(user-level) ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(์˜ˆ๋ฅผ ๋“ค๋ฉด, GNU Pth)๋“ค๊ณผ์˜ ์ฐจ์ด์ ์€ ๋ญ์ฃ ? #

UNIX ํ˜ธํ™˜ ์šด์˜์ฒด๊ณ„๋ฅผ ์œ„ํ•œ ๋ช‡๋ช‡ ์‚ฌ์šฉ์ž ์ˆ˜์ค€ ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค(์˜ˆ๋ฅผ ๋“ค๋ฉด [http]GNU Pth, [http]Patched MIT Pthreads๋“ฑ๋“ฑ์„ ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค). ์ด๋“ค ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋“ค ์ค‘ ๋งŽ์€ ์ˆ˜๊ฐ€, ๋‹จ์ผ ํ”„๋กœ์„ธ์Šค ์ฃผ์†Œ๊ณต๊ฐ„์ƒ์—์„œ์˜ ํ˜‘๋ ฅ์  ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์Šค์ผ€์ค„๋ง(ๅคš๋Œ€1 ๋ชจ๋ธ)๊ณผ ๊ฐ™์€, ST์™€ ๋™์ผํ•œ ๊ฐœ๋…์ƒ์—์„œ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ST๋Š” ๋‹ค๋ฅธ ๋ชฉํ‘œ์™€ ๊ฐœ๋ฐœ ์šฐ์„ ์ˆœ์œ„๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์œผ๋ฏ€๋กœ, ๊ตฌํ˜„ ๋˜ํ•œ ์ด๋“ค๊ณผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, GNU Pth์˜ ๊ฐœ๋ฐœ์ƒ์˜ ์ผ์ฐจ์ ์ธ ์šฐ์„ ์ˆœ์œ„๋Š” ํ”Œ๋ ›ํผ ๋…๋ฆฝ์ ์ด๊ณ  ๋ชจ๋“  ํ”Œ๋ ›ํผ์„ ์•„์šฐ๋ฅด๋Š”๋ฐ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด์— ST๋Š” ๋ชจ๋“  ๋ช…์‹œ๋œ ํ”Œ๋ ›ํผ์— ๋Œ€ํ•ด ๊ณ ์„ฑ๋Šฅ, ํ™•์žฅ์„ฑ, ์ •ํ™•์„ฑ์„ ์–ป๋Š” ๊ฒƒ์„ ๋ชฉ์ ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค. ST์˜ API์™€ ๋‚ด๋ถ€๋Š” ํŠน์ • ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์˜์—ญ์˜ ํ•„์š”์œ„์ฃผ๋กœ ๋””์ž์ธ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์“ฐ๋ ˆ๋“œ์˜ ์„ ์ ์  ํ˜น์€ ์šฐ์„ ์ˆœ์œ„ ๊ธฐ๋ฐ˜์˜ ์Šค์ผ€์ค„๋ง์€ ๋‚ฎ์€ ์“ฐ๋ ˆ๋“œ ๊ด€๋ฆฌ์ƒ์˜ ๊ณผ๋ถ€ํ•˜๋ฅผ ๊ณ ๋ คํ•˜์—ฌ ์ƒ๋žต๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์“ฐ๋ ˆ๋“œ ์ƒ์„ฑ ๋ฐ ๋ฌธ๋งฅ ์ „ํ™˜์„ ์œ„ํ•œ ์‹œ์Šคํ…œ ํ˜ธ์ถœ ์ˆ˜๋Š” ๊ฐ€๋Šฅํ•œํ•œ ์ตœ์†Œํ™”ํ•˜๋„๋ก ์ž‘์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์“ฐ๋ ˆ๋“œ๋ณ„ ์‹œ๊ทธ๋„ ๋งˆ์Šคํฌ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ, ์“ฐ๋ ˆ๋“œ์˜ ๋ฌธ๋งฅ์ „ํ™˜๋งˆ๋‹ค ํ”„๋กœ์„ธ์Šค ์‹œ๊ทธ๋„ ๋งˆ์Šคํฌ๋ฅผ ์ €์žฅํ•˜๊ฑฐ๋‚˜ ๋ณต๊ตฌํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

์š”์•ฝํ•˜๋ฉด, ST๋Š” ์ผ๋ฐ˜์ ์ธ ์šฉ๋„์˜ ์“ฐ๋ ˆ๋“œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ๋Œ€ํ•œ ์ „์ฒด ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ธฐ์œ„ํ•ด์„œ ๋””์ž์ธ ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.(์–ด๋–ค ๋ฐฉ๋ฒ•์ด๋“  ์ด๊ฒƒ์€ ์ปค๋„ ๊ธฐ๋Šฅ์ง€์›์ด ์—†์ด๋Š” ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค) ๋Œ€์‹ ์— ST๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ด๋ฒคํŠธ ๊ธฐ๋ฐ˜ ์ƒํƒœ ๊ธฐ๊ณ„๋กœ ๊ตฌ์„ฑํ•˜๊ธฐ์œ„ํ•œ ์“ฐ๋ ˆ๋“œ API๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

5 ๋‹ค์ค‘ CPU์ƒ์—์„œ ST๋Š” ์–ด๋–ค ์ž‡์ ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‚˜์š”? #

๋‹ค์ค‘ ํ”„๋กœ์„ธ์Šค ์‹œ์Šคํ…œ์ƒ์—์„œ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ํ•˜๋“œ์›จ์–ด ๋ณ‘๋ ฌ์ฒ˜๋ฆฌ์˜ ์ž‡์ ์„ ์–ป๊ธฐ ์œ„ํ•ด ๋‹ค์ˆ˜์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.(๊ทธ๋ฆผ 3)๊ฐ ํ”„๋กœ์„ธ์Šค๋Š” ๋‹ค์ค‘ ์ƒํƒœ ์“ฐ๋ ˆ๋“œ๋ฅผ ๊ตฌ๋™ํ•˜๋Š” "๊ฐ€์ƒ ํ”„๋กœ์„ธ์„œ"๋กœ์„œ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœ์„ธ์Šค๊ด€๋ฆฌ๋Š” ST์˜ ๋ฒ”์ฃผ์— ๋“ค์ง€ ์•Š์œผ๋ฉฐ, ๋Œ€์‹ ์— ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ชซ์œผ๋กœ ๋‚จ๊ฒจ๋‘๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””์ž์ด๋„ˆ๋Š” ์–ผ๋งˆ๋‚˜ ๋งŽ์€ ์ˆ˜์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ƒ์„ฑํ•  ๊ฒƒ์ธ๊ฐ€์™€ ํ‘œ์ค€ IPC(ํ”„๋กœ์„ธ์Šค๊ฐ„ ํ†ต์‹ ) ์žฅ์น˜๋ฅผ ํ†ตํ•˜์—ฌ ์ด๋“ค ํ”„๋กœ์„ธ์Šค๊ฐ„์— ๋ฌด์Šจ ์ž์›์„ ๊ณต์œ ํ•  ๊ฒƒ์ธ๊ฐ€๋ฅผ ๋ชจ๋‘ ๊ฒฐ์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


Using multiple processes allows to avoid synchronization overhead on multiprocessor systems and thus achieve high system scalability. It is often better to have several separate smaller process-specific resources (such as data caches) than one large resource shared and modified by all processes. In other words, each process should be considered as a separate mini-instance of the application ("cluster in a box" approach). This multi-process multi-threaded architecture also increases an application's availability because each process works as a fault container. If one of the processes crashes, only a fraction of all threads (user connections) will be lost.

6 ST๋Š” ๋””์Šคํฌ ์ž…์ถœ๋ ฅ์„ ์–ด๋–ป๊ฒŒ ๋‹ค๋ฃจ๋‚˜์š”? #

All event-driven state machine implementations (including both ST and traditional EDSMs) have the same drawback. Certain operations on disk files (read(), stat(), open() and others) or a page fault may block the entire process while disk I/O is in progress. Setting non-blocking mode on a file descriptor corresponding to a disk file has no effect on most UNIX-like operating systems. In this respect ST is no different than traditional EDSMs.

To more efficiently multiplex disk I/O, multiple identical application processes may be created (Figure 3). The probability that at any given moment all processes are blocked on disk I/O exponentially decreases with the number of processes. This approach ("symmetric EDSM") is used, for example, by the [http]Zeus Web server. Another approach is to delegate blocking disk I/O operations to a special set of helper processes or kernel threads ("asymmetric EDSM"). This technique is used by the [http]Squid Web proxy server and [http]Flash Web server. In any case, it is up to the application designer to choose the most optimal architecture for the specific application at hand.


7 ST์˜ ์ด์‹์„ฑ์€ ์–ด๋–ป์Šต๋‹ˆ๊นŒ? #

ST๋Š” ๋ช‡๋ช‡ UNIX ํ˜ธํ™˜ ํ”Œ๋ ›ํผ์ƒ์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์šด์˜์ฒด๊ณ„ ๊ธฐ๋Šฅ์— ์˜์กดํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. That makes it very portable across many flavors of UNIX. ํ˜„์žฌ ST๋Š” ๋ฆฌ๋ˆ…์Šค, ์†”๋ผ๋ฆฌ์Šค, IRIX, BSD ๊ณ„์—ด ์šด์˜์ฒด๊ณ„, ๊ทธ์™ธ ๋‹ค๋ฅธ ์šด์˜์ฒด๊ณ„์—์„œ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค. ์‹ฌ์ง€์–ด Win32 ์‹œํ—˜์ด์‹ํŒ๋„ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. (ํ˜„์žฌ๋Š” 1.0์ด ์žˆ์Œ. ์•ˆ์ •์ .)

The only part of the library which needs special attention when porting to a new platform is the thread context initialization. ST uses the _setjmp()/_longjmp() routines or their variants to save/restore the machine context. The machine context consists of CPU registers including the program counter (PC) and the stack pointer (SP). It is usually initialized by calling _setjmp() to get the initial state and then manually setting the SP field of the jmp_buf structure to a newly allocated stack segment:

    struct thread {
        ...
        jmp_buf context;
        ...
    };

    ...
    struct thread *t;
    ...

    /* Get the initial state including PC */
    if (_setjmp(t->context)) {
        /* This function never returns */
        thread_main_function(); 
    }

    /* Now set SP to a new value */
    ...

There are several ways to find out the exact location of the SP field in the jmp_buf structure. For many platforms ST just borrows the relevant code from [http]NSPR, but other methods can be used as well. For example, on open source platforms it is possible to look at the _setjmp() implementation and figure out where SP is saved even without any special skills in platform-specific assembly language. Another approach is to run special "probing" code which explores the jmp_buf structure and reports the SP location. A [http]minimal user-level thread package by Douglas W. Jones uses this technique. In any case, most of the work should be done up front to avoid any overhead during library initialization or, even worse, every time a thread is created.

8 ๋ฐฐํฌ๋˜๋Š” ST๋Š” ์–ด๋–ค ๋ผ์ด์„ผ์Šค๋ฅผ ์ ์šฉํ•˜๊ณ  ์žˆ๋‚˜์š”? #

ST๋Š” Mozilla Public License (MPL) ๋ฒ„์ „ 1.1 ๋˜๋Š” GNU General Public License (GPL) ๋ฒ„์ „ 2 ๋˜๋Š” ๊ทธ ์ดํ›„ ๋ฒ„์ „์„ ๋”ฐ๋ฅด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ๋ถ„์€ ์ด ๋‘๊ฐ€์ง€ ๋ผ์ด์„ผ์Šค ์ค‘ ํ•˜๋‚˜๋ฅผ ํƒํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋‘˜๋‹ค๋ฅผ ์ ์šฉํ•ด๋„ ์ข‹์Šต๋‹ˆ๋‹ค. ์ƒ์—…์ ์ธ ์šฉ๋„๋ผ๋ฉด ์•„๋งˆ๋„ MPL์„, ์ž์œ  ์†Œํ”„ํŠธ์›จ์–ด๋ผ๋ฉด GPL์„ ์„ ํ˜ธํ•˜๋ฆฌ๋ผ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

์š”์•ฝํ•˜์ž๋ฉด, ST๋Š” ์–ด๋– ํ•œ ๋‹ค๋ฅธ ์†Œํ”„ํŠธ์›จ์–ด(๊ณต๊ฐœ๊ฑด ๋น„๊ณต๊ฐœ๊ฑด๊ฐ„์—) ์ œ์•ฝ์—†์ด ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ST ์ž์ฒด์— ๋Œ€ํ•œ ์ˆ˜์ •์‚ฌํ•ญ๋“ค์€ ์—ฌ๋Ÿฌ๋ถ„์˜ ์ˆ˜์ •๋œ ๋ฒ„์ „์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“  ์‚ฌ๋žŒ๋“ค์ด ์•Œ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

9 ST๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์žฅ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? #

ST๋Š” ์ „ํ†ต์ ์ธ ๊ฒฐ์ •์œ„์ฃผ์˜ ๋™์ž‘, ๊ณ ์„ฑ๋Šฅ, ๋‹ค์ˆ˜์˜ ๋™์‹œ์ฒ˜๋ฆฌ ์‚ฌ์šฉ์ž ์ง€์›๊ธฐ๋Šฅ๊ณผ ๊ฐ™์€ EDSM์˜ ์žฅ์ ๋“ค์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋™์‹œ์—, ST๋Š” ์“ฐ๋ ˆ๋“œ ๊ฐœ๋…์„ ์‚ฌ์šฉํ•จ์œผ๋กœ์„œ ์ž์—ฐ์Šค๋Ÿฐ ์„ ํ˜•์  ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๋ชจ๋ธ์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค. ST-๊ธฐ๋ฐ˜์˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ฑฐ๋‚˜ ํ™•์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

10 ST๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ ์žˆ์–ด ๋‹จ์ ์€ ๋ฌด์—‡์ž…๋‹ˆ๊นŒ? #

ST์˜ ์ฃผ๋œ ๋‹จ์ ์€ ์†Œ์ผ“์ƒ์˜ ๋ชจ๋“  ์ž…์ถœ๋ ฅ ๋ช…๋ น์€ ST์˜ ์ž…์ถœ๋ ฅ ํ•จ์ˆ˜๋“ค์„ ์‚ฌ์šฉํ•ด์•ผ๋งŒ ํ•œ๋‹ค๋Š” ์ ์ž…๋‹ˆ๋‹ค. ๋‹จ์ง€ ST์˜ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์•ผ๋งŒ ์“ฐ๋ ˆ๋“œ ์Šค์ผ€์ค„๋ง์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ณ  ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ํ”„๋กœ์„ธ์Šค๊ฐ€ ๋ธ”๋Ÿญ๋˜๋Š” ๊ฒƒ์„ ๋ง‰์•„์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-10-28 12:42:54
Processing time 0.4924 sec