Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
goroutineとマルチスレッドデザインパターン/ goroutine and multit...
Search
nametake
December 08, 2016
Programming
1
1.3k
goroutineとマルチスレッドデザインパターン/ goroutine and multithreaded design pattern
https://connpass.com/event/28621/
Go言語LT大会! 「最近、Go言語始めました」の会での発表資料
nametake
December 08, 2016
Tweet
Share
More Decks by nametake
See All by nametake
実例マッピングで要件のレビューサイクルを回してる話 / Example Mapping Review Cycle
nametake
1
1.1k
アルプ T-QAオンボーディング資料(2022年9月版) / Alp T-QA onboarding 2022-09
nametake
0
1.5k
定式化と自動化に取り組みますという話 / Work on formulation and automation
nametake
0
890
QAエンジニアが実例マッピングを2ヶ月運用した話 / Example Mapping for 2 months
nametake
3
5.8k
1人目QAエンジニアよもやま話 / QA Test Talk Vol.1
nametake
4
650
アルプでのAgile Testing / Alp Agile Testing
nametake
1
2.2k
CFD-Editorというツールを作ってみた話 / Made CFD-Editor
nametake
1
310
スタートアップで1人目QAエンジニアになった話 / Startup first QA
nametake
3
1.3k
テスト技法の話 / Testing techniques
nametake
5
4.6k
Other Decks in Programming
See All in Programming
103 Early Hints
sugi_0000
1
220
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.6k
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
630
ソフトウェアの振る舞いに着目し 複雑な要件の開発に立ち向かう
rickyban
0
890
Haze - Real time background blurring
chrisbanes
1
500
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
200
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
CSC305 Lecture 26
javiergs
PRO
0
140
선언형 UI에서의 상태관리
l2hyunwoo
0
140
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
530
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Music & Morning Musume
bryan
46
6.2k
Scaling GitHub
holman
458
140k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
A better future with KSS
kneath
238
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
For a Future-Friendly Web
brad_frost
175
9.4k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
KATA
mclloyd
29
14k
Transcript
goroutineͱ ϚϧνεϨου σβΠϯύλʔϯ ߦ লޗ
ࣗݾհ • ߦ লޗ(φϝΩ γϣΰ) • 2016৽ଔ • Goݴޠྺ 5ϲ݄
goroutineͬͯ·͔͢?
GoݴޠΛޠΔ্Ͱ ֎ͤͳ͍ฒྻԽͷػೳ
͜ͷ͍ํ͋ͬͯΔʁ ͢ΕͬͲ͜Θ͍
goroutineͷߟ͑ํͱ σβΠϯύλʔϯ
GoͰͷฒߦॲཧ
υΩϡϝϯτΛॲ͢Δࣄ υΩϡϝϯτͷࢁ ম٫ Gopher͘Μͱ Χʔτ ͨ͘͞Μ͋ΔυΩϡϝϯτΛ೩͍ͨ͠
୯७ͳΞϓϩʔν Gopher͘ΜΛ2ඖ(ਓ?)ʹ
ಉظ͕ͪൃੜͯ͠͠·͏ ম٫Λ͑Δͷ1ʹ1ඖ(ਓ?)
ಉظ͕ͪൃੜͯ͠͠·͏ ম٫Λ͑Δͷ1ʹ1ඖ(ਓ?)
૿ͯ͠ޮՌ্͕͕ΓͮΒ͍
GoݴޠͰͷΞϓϩʔν
ฒྻͳॲཧ Gopher͘ΜΛฒྻʹಈ͔͢ͷͰͳ͘
ฒߦͳॲཧ Gopher͘ΜΛฒߦʹಈ͔͢
ฒߦͳॲཧ υΩϡϝϯτΛΧʔτʹੵΉGopher͘Μ
ฒߦͳॲཧ ΧʔτΛӡͿGopher͘Μ
ฒߦͳॲཧ υΩϡϝϯτΛΧʔτ͔Β͓Ζͯ͠ ೩͢Gopher͘Μ
ฒߦͳॲཧ υΩϡϝϯτΛੵΜͰ͍ͨ ΧʔτΛ͢Gopher͘Μ
Կ͕خ͍͠ͷ͔
ॲཧΛͨͳͯ͘ྑ͍
ॲཧΛͨͳͯ͘ྑ͍ ӡͿͷ͕ࣄ
ॲཧΛͨͳͯ͘ྑ͍ ೩͠ऴΘΔͷΛ ͨͳ͍
Δ͜ͱ͕ͳ͚Εࢭ·Δ͚ͩ
͜ΕΒΛ࣮ݱ͢Δػೳ • channel • Gopher͘ΜͷؒΛܨ͍Ͱ͘ΕΔ • ෳͷGopher͘Μ͕channelΛୣ͍߹͏ͷΛ͙ • select •
ෳͷGopher͘Μ͔ΒຊΛड͚औΕΔ • mutexͷύοέʔδͱ͔
ϚϧνεϨου σβΠϯύλʔϯ
ϚϧνεϨου σβΠϯύλʔϯ • Single Thread Execution • Immutable • Guarded
Suspension • Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
channelͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
selectͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
ύοέʔδͰղܾ • Single Thread Execution • Immutable • Guarded Suspension
• Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
ؾΛ͚ͭͳ͍ͱ͍͚ͳ͍͜ͱ
ϚϧνεϨου σβΠϯύλʔϯ • Single Thread Execution • Immutable • Guarded
Suspension • Balking • Producer-Consumer • Read-Write Lock • Thread-Per-Message • Worker Thread • Future • Two-Phase Termination • Thread-Specific Storage • Active Object
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ υΩϡϝϯτΛड͚औͬͨΒ……
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ ͦΕຖʹGopher͘ΜΛ࡞Δ
Thread-Per Message • ϝοηʔδΛड͚औΔຖʹεϨουΛཱͯΔ
GoͩͱΓ͕ͪ func processHandler(w http.ResponseWriter, r *http.Request) { ~~~όϦσʔγϣϯͱ͔Payloadऔಘͱ͔~~ go Heavy()
// ͜ͷ෦ʂʂʂ w.WriteHeader(http.StatusAccepted) }
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ υΩϡϝϯτΛ ड͚औͬͨΒ…… !
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ۭ͍ͯΔ ୭͔͕୲
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ! ·ͨདྷͨΒ……
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ ۭ͍ͯΔ ୭͔͕୲
Worker Thread • ࠷ॳ͔ΒεϨουΛಈ͔͓ͯ͘͠ Gopher͘Μͷ ૿͑ͳ͍
channelͩͱ؆୯ func heavy(queue <-chan string) { url := <-queue //
ϦΫΤετॲཧ } func main() { queue := make(chan string, 32) for i := 0; i < 3; i++ { go heavy(queue) } queue <- “https://google.co.jp” queue <- “https://google.com” // লུ }
͜ΕͰ͏goroutine ා͘ͳ͍ʂʂʂ
Α͖goroutineϥΠϑΛ!!!