- up: 📁並行プログラミング
共有メモリモデル
Shared-State concurrency.
たぶん最もメジャーな並列プログラミングパラダイム.
共有メモリモデルの基礎概念
📝共有メモリ
複数のプログラムが同時並行的にアクセスするメモリ領域.
プログラム間で情報をやり取りするための効率的な手段.
排他制御
Mutual exclusion locks.
define a “critical section” that can only be executed by one thread at a time
逆に言えば, 共有メモリを使わないモデルならば排他制御をかんがえなくていいという利点がある.
リエントラント
Reentrant.
プログラムやサブルーチンが, 実行の途中で割り込まれ, その実行が完了する前に再び呼び出され実行されても安全だという性質.
複数のスレッドから同時に呼び出されても正しく動作する関数.
ref. リエントラント - Wikipedia
スピンロック
Spin Lock
スレッドがロックを獲得できるまで単純にループ (スピン)して定期的にロックをチェックしながら待つ方式.
ref. スピンロック - Wikipedia
再入可能ロック
再入可能ロック, Reentrant Lock, Sleep Lock.
Android API: ReentrantLock | Android Developers
A reentrant mutual exclusion lock that extends the built-in monitor lock capabilities.
ReadWriteLock
Readers-Writerlock, ともいわれる.
WriteLock Improves performance when resources are read much more often than written.
It allows multiple threads to read a certain resource, but only one to write it, at a time.
ref. Read / Write Locks in Java
セマフォ
並列プログラミング環境での複数のプロセスが共有する資源にアクセスするのを制御する際の単純だが便利な抽象化を提供する変数または抽象データ型.
ref. セマフォ - Wikipedia
A non-negative integer that controls the access of multiple threads to a limited number of shared resources
A semaphore can be atomically incremented & decremented to control access to a shared resource
語源は, 腕木式信号機.
カウンティングセマフォ
Counting Semaphores. 任意個の資源を扱うセマフォ.
バイナリセマフォ
Binary Semaphores.
値が 0 と 1 に制限されている (ロック/ アンロック, 使用可能/ 使用不可の意味がある) セマフォ.
ミューテックスとも.
Condition Value
条件変数. UNIX の用語.
ミューテックスと一緒に使用し, スレッドをブロックして別のスレッドからのシグナルを待たせる. 通知がくることがポイント.
ref. ミューテックス, セマフォ, 条件変数, 違いを整理してみよう - Schi Heil と叫ぶために
Block thread (s) until some condition (s) becomes true
-
wait
-
signal
-
signalAll
-
cf. 📝データフロー変数は言語レベルでサポートされている並行機構.
-
refs. Guarded suspension
ConditionObject (Java)
Java では, ConditionObject として提供される.
AbstractQueuedSynchronizer.ConditionObject (Java Platform SE 6)
Barrier
他のスレッドをある地点でまち合わせて, 一度にさせること. 競馬のスタートバーのようなイメージ.
または, 旅行のツアーガイド. 集合時間が決められていてる.
CountDownLatch (Java)
Allows one or more threads to wait until a set of operations being performed in other threads complete
CountDownLatch (Java Platform SE 6)