「Example17.5」の編集履歴(バックアップ)一覧はこちら
Example17.5 - (2010/09/17 (金) 11:51:59) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
**17.5 Semaphores
**17.5 セマフォ
A common mechanism for process synchronization is a lock (or: semaphore). A lock offers two atomic actions: acquire and release. Here's the implementation of a lock in Scala:
プロセス同期の一般的なメカニズムはロック(あるいはセマフォ)です。ロックは2つのアトミックなアクションを提供します。すなわち、獲得と解放です。次は Scala におけるロックの実装です。
package scala.concurrent
class Lock {
var available = true
def acquire = synchronized {
while (!available) wait()
available = false
}
def release = synchronized {
available = true
notify()
}
}
----
#comment