アットウィキロゴ

Example17.5

「Example17.5」の編集履歴(バックアップ)一覧に戻る

Example17.5 - (2011/02/24 (木) 09:13:50) のソース

#co(){
17.5 Semaphores

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:
}


#setmenu2(ex-r-menu)
** 17.5 セマフォ

プロセス同期の一般的なメカニズムは&bold(){ロック} (あるいは&bold(){セマフォ}) です。ロックは2つのアトミックなアクションを提供します。すなわち、&bold(){獲得}と&bold(){解放}です。次は Scala におけるロックの実装です。

  package scala.concurrent
 
  class Lock {
    var available = true
    def acquire = synchronized {
      while (!available) wait()
      available = false
    }
    def release = synchronized {
      available = true
      notify()
    }
  }

#center(){[[前ページ>Example17.4]] [[ 17 章>Chapter 17 Abstractions for Concurrency]] [[目次>ScalaByExample和訳]] [[次ページ>Example17.6]]}

----
#comment
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。