Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
チャンネルを完全に理解する
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Senoue
December 11, 2024
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
チャンネルを完全に理解する
Sendai.go2024年12月11日のLTしたい資料です。
Senoue
December 11, 2024
More Decks by Senoue
See All by Senoue
Go(5)分で! ECC暗号を動かして理解する BuriKaigi 2026
senoue
2
110
Goカードゲームを 作ってみた!
senoue
0
320
App_RunnerとRDSを活用したスケーラブルなWebAPI構築とインフラの自動化.pdf
senoue
1
160
Real-time Communication in Go with Melody and WebSockets
senoue
0
200
Adobeの生成AIのこと を調べてみた
senoue
0
250
ソフトウェア開発におけるAI :CopilotとGenie
senoue
0
240
Sendai.go x GDG Cloud 仙台 ハンズオン
senoue
0
92
GoでMecab
senoue
0
420
GKEとGoでエフェメラルなサービス
senoue
0
430
Other Decks in Programming
See All in Programming
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
200
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
350
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
460
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
150
スマート反転とウェブアクセシビリティ
camiha
0
210
XHTMLが残したもの
yosuke_furukawa
PRO
2
820
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
550
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
120
setup-vp GitLab対応の裏側
naokihaba
0
110
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
190
速習iPhone Duo対応
yuukiw00w
1
650
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
WENDY [Excerpt]
tessaabrams
14
39k
How to Ace a Technical Interview
jacobian
281
24k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
510
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
380
Design in an AI World
tapps
1
320
Building the Perfect Custom Keyboard
takai
2
880
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Technical Leadership for Architectural Decision Making
baasie
3
570
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Transcript
Goのチャネル を完全に理解する 瀬上祐匡 2024/12/11
瀬上 祐匡(せのうえ ひろまさ) 株式会社クラウドスミス テクニカルマネージャー • AWS,GCP, Go, Python等,BI,データ分析 •
@senoue,@hiromasa.senoue • モノノフです。 • 好きなものは、Cloud Function • Sendai.go やってます • TynyGo-keebなど 自己紹介 株式会社クラウドスミス 仙台を拠点とした、Webシステム中心の開発会社です。
- 定義: - チャンネルは、 Goroutine間でデータを送受信 するためのパイプです。 - 特徴: - 型指定される。
- 複数のGoroutineから安全にデータを共有で きる同期機構がある。 1. チャンネルとは?
- a. 宣言と作成 - - b. 送信と受信 - c. バッファ付きチャンネル
2. チャンネルの基本操作 ch := make(chan int) // 整数 ch <- 10 // 送信 value := <-ch // 受信 ch := make(chan int, 3) // バッファサイズ 3 のチャンネル
- a. Goroutine間通信 - 3. 実践的な使用例 func worker(id int, ch
chan int) { for n := range ch { fmt.Printf("Worker %d received %d\n", id, n) } } func main() { ch := make(chan int) for i := 0; i < 3; i++ { go worker(i, ch) } for i := 0; i < 5; i++ { ch <- i } close(ch) } 実際の動作:https://go.dev/play/p/K54rceX7AUn
- b. select を用いた多重チャネル操作 - 3. 実践的な使用例 func main() {
ch1 := make(chan string) ch2 := make(chan string) go func() { ch1 <- "from channel 1" }() go func() { ch2 <- "from channel 2" }() for i := 0; i < 2; i++ { select { case msg1 := <-ch1: fmt.Println(msg1) case msg2 := <-ch2: fmt.Println(msg2) } } }
- デッドロック : 送られた値を誰も受け取らない場 合、または相手がいない場合に発生。 - Channelの適切なクローズ (close) が必要。 -
Goroutineリーク: 終了条件なく走り続ける Goroutineを避ける。 4. 注意点とベストプラクティス
- デモ 4. 注意点とベストプラクティス
まとめ
- チャネルによって、ゴルーチン間の通信や同期がシ ンプルになります。 明示的なロック機構( sync.Mutexなど)を使用せず に済むため、コードがわかりやすくなります。 - チャネルを使ってタスクをキューに入れることがで き、ワーカーゴルーチンで並列に処理することができ ます。
これにより、負荷の高いタスクの分散処理が容易に なります。 5. メリット
- バッファなしチャンネルとバッファありチャンネルの 違いは? - バッファなしは同期的、バッファありは非同期 的に動作できます。 ただし、バッファがいっぱいになるとブロックさ れます。 - なぜチャンネルを使うべきなのか?
- 安全にデータをやりとりし、同期させるために 有用だからです。 5. まとめ
Thank You