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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ryo takaya
May 24, 2023
18
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
並行処理(超入門)
ryo takaya
May 24, 2023
More Decks by ryo takaya
See All by ryo takaya
軽量なスレッドとは?
ryotakaya
0
150
PHP8.0へのバージョンアップ始めました
ryotakaya
0
780
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
370
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
580
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Tell your own story through comics
letsgokoyo
1
1.1k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
Git: the NoSQL Database
bkeepers
PRO
432
67k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
470
Raft: Consensus for Rubyists
vanstee
141
7.7k
Between Models and Reality
mayunak
4
450
sira's awesome portfolio website redesign presentation
elsirapls
0
410
Transcript
並行処理(超入門)
並行処理をしたら何が嬉しいのか 複数の処理を分散並行して行う事によって処理時間が短縮する - DBの読み込みの性能を上げる工夫(indexとか) - http通信でユーザーへのレスポンスを短くするための工夫(CDNとか) 基本的に速さは正義
並行処理と並列処理の違い 時間軸の違い • 並行処理: ある時間の範囲において、複数のタスクを扱うこと • 並列処理: ある時間の点において、複数のタスクを扱うこと 必ずしも同時に実行されているわけではない
並行処理は考えなきゃいけないポイントが多々ある - その処理は並列化をしたら早くなるのか?? - 必ず早くなるとは限らない - (ex. 順序に意味のある処理 - アムダールの法則
- 競合状態 - 共通のメモリにアクセス - データ競合、ロック
goroutine - プログラムを動作させる基本の単位 - goキーワードを記述するだけ
- fork-joinモデル - プログラムの処理を分岐させて親と子で並行に実行する - fork : goroutineを発生させて分岐する - join
: 分岐元の親のgoroutineと合流する 分岐元のgoroutineが先に終了した場合、分岐先のgoroutineが実行されず終了する
sync.WaitGroup 1. wg.Add()でカウンタを増やす 2.wg.Done()でカウンタを減らす 3.wg.Wait()で内部のカウンタが 0になるまでブロックする Wait()が合流ポイントとなっているため分岐先のgoroutineが実行が終わるまで分岐元 のgoroutineが終了しない
- Mutex - Locker - Cond https://pkg.go.dev/sync
channel ゴールーチン間で値を受け渡す際に使用する
- 値を送信・受信するまでブロックする - 3秒たってchannelに値を送信。その後分岐元の goroutineでchannelから値を受け取るまでブロック する。 channelは同期の手段でもある
None