アットウィキロゴ

Example17.5]

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()
   }
 }

名前:
コメント:

タグ:

+ タグ編集
  • タグ:
最終更新:2010年09月17日 11:51
ツールボックス

下から選んでください:

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