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
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
Exploring: Partial and Independent Composables
blackbracken
0
100
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
340
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Spatial Rendering for Apple Vision Pro
warrenm
0
110
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
340
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
210
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
150
テストコード書いてみませんか?
onopon
2
130
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
340
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.5k
Producing Creativity
orderedlist
PRO
341
39k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Designing for humans not robots
tammielis
250
25k
Writing Fast Ruby
sferik
628
61k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The Cost Of JavaScript in 2023
addyosmani
45
7k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
What's in a price? How to price your products and services
michaelherold
243
12k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
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ϥΠϑΛ!!!