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.2k
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
980
アルプ T-QAオンボーディング資料(2022年9月版) / Alp T-QA onboarding 2022-09
nametake
0
1.4k
定式化と自動化に取り組みますという話 / Work on formulation and automation
nametake
0
840
QAエンジニアが実例マッピングを2ヶ月運用した話 / Example Mapping for 2 months
nametake
3
5.4k
1人目QAエンジニアよもやま話 / QA Test Talk Vol.1
nametake
4
620
アルプでのAgile Testing / Alp Agile Testing
nametake
1
2.1k
CFD-Editorというツールを作ってみた話 / Made CFD-Editor
nametake
1
290
スタートアップで1人目QAエンジニアになった話 / Startup first QA
nametake
3
1.3k
テスト技法の話 / Testing techniques
nametake
5
4.6k
Other Decks in Programming
See All in Programming
KSPの導入・移行を前向きに検討しよう!
shxun6934
PRO
0
220
開発を加速する共有Swift Package実践
elmetal
PRO
0
410
ECMAScript、Web標準の型はどう管理されているか / How ECMAScript and Web standards types are maintained
petamoriken
3
390
マイグレーションコード自作して File-Based Routing に自動移行!! ~250 ページの歴史的経緯を添えて~
cut0
1
260
Architecture Decision Record (ADR)
nearme_tech
PRO
1
680
How to Break into Reading Open Source
kaspth
2
210
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
Android開発以外のAndroid開発経験の活かしどころ
konifar
2
950
Swiftコードバトル必勝法
toshi0383
0
150
月間4.5億回再生を超える大規模サービス TVer iOSアプリのリアーキテクチャ戦略 - iOSDC2024
techtver
PRO
1
890
o1モデルのプロンプトエンジニアリングって?
ktc_wada
0
140
メモリ最適化を究める!iOSアプリ開発における5つの重要なポイント
yhirakawa333
0
410
Featured
See All Featured
Infographics Made Easy
chrislema
239
18k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.9k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
227
52k
What's new in Ruby 2.0
geeforr
340
31k
Done Done
chrislema
180
16k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
109
6.9k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
A Tale of Four Properties
chriscoyier
155
22k
Optimizing for Happiness
mojombo
375
69k
BBQ
matthewcrist
83
9.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
36
6.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
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ϥΠϑΛ!!!