コンテンツにスキップ

モニタ (同期)

出典: フリー百科事典『ウィキペディア(Wikipedia)』

: monitor1: condition variable



Concurrent Pascal Solo Operating System 使

使

[]


:












monitor account {
  int balance := 0
  
  function withdraw(int amount) {
    if amount < 0 then error "Amount may not be negative"
    else if balance < amount then error "Insufficient funds"
    else balance := balance - amount
  }
  
  function deposit(int amount) {
    if amount < 0 then error "Amount may not be negative"
    else balance := balance + amount
  }
}

 balance Eiffel

[]


condition variable使

使1
monitor channel {
  int contents
  boolean full := false
  condition snd
  condition rcv

  function send(int sent) {
    if full then wait(rcv)
    contents := sent
    full := true
    notify(snd)
  }

  function receive() {
    var int received

    if not full then wait(snd)
    received := contents
    full := false
    notify(rcv)
    return received
  }
}





[?] iftest then wait(cv)  wait(cv)  while test dowait(cv) 



:
conditionVariable{
  int queueSize = 0;
  semaphore lock;
  semaphore waiting;
  
  wait(){
     lock.acquire();
     queueSize++;
     lock.release();
     waiting.down();
  }
  
  signal(){
     lock.acquire();
     if (queueSize > 0){
        waiting.up();
     }
     lock.release();
  }
}

[]


Per Brinch Hansen 



Concurrent Pascal

C#VB.NET.NETSystem.Threading.Monitor[1][ 1]

C++C++11C++std::mutexstd::condition_variable[3][4]

JavaObject.wait()Object.notify()Java 1.5LockCondition

DelphiSystem.SyncObjs.TConditionVariableMutex[5]

Mesa

Python

Ruby

Squeak Smalltalk

POSIX (Pthreads) pthread_mutex_tpthread_cond_t[6]Boost C++boost::mutexboost::condition_variable[7]POSIXPthreadsC++11Windows APIBoostWin32使[8]Microsoft Windows VistaMicrosoft Windows Server 2008API[9]

脚注[編集]

注釈[編集]

  1. ^ .NETのMonitorは単純なミューテックスを実現するためのクラスでもあり、C#やVB.NETなどのlockステートメントは、コンパイラによって内部的にはMonitorクラスを使用したコードに展開される[2]

出典[編集]

外部リンク[編集]