るりまサーチ

最速Rubyリファレンスマニュアル検索!
90件ヒット [1-90件を表示] (0.153秒)
トップページ > クエリ:t[x] > クエリ:Thread[x] > クエリ:ConditionVariable[x]

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. fiddle sizeof_ssize_t
  4. fiddle align_size_t
  5. fiddle sizeof_size_t

ライブラリ

クラス

キーワード

検索結果

ConditionVariable (44032.0)

Alias of Thread::ConditionVariable

...Alias of Thread::ConditionVariable...

Thread::ConditionVariable (27066.0)

スレッドの同期機構の一つである状態変数を実現するクラスです。

...一つである状態変数を実現するクラスです。

以下も ConditionVariable を理解するのに参考になります。

https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとしま...
...でも空くことはありません。

以上のような状況を解決するのが Condition Variable です。

スレッド a で条件(リソースが空いているかなど)が満たされるまで wait メソッドで
スレッドを止めます。他のスレッド b において条件が...
...です。

mutex = Mutex.new
cv = ConditionVariable.new

a = Thread.start {
mutex.synchronize {
...
while (条件が満たされない)
cv.wait(mutex)
end
...
}
}

b = Thread.start {
mutex.synchronize {...

Thread::ConditionVariable#wait(mutex, timeout = nil) -> self (12194.0)

mutex のロックを解放し、カレントスレッドを停止します。 Thread::ConditionVariable#signalまたは、 Thread::ConditionVariable#broadcastで送られたシグナルを 受け取ると、mutexのロックを取得し、実行状態となります。

...mutex のロックを解放し、カレントスレッドを停止します。
Thread
::ConditionVariable#signalまたは、
Thread
::ConditionVariable#broadcastで送られたシグナルを
受け取ると、mutexのロックを取得し、実行状態となります。

@param mutex Thread::Mutex...
...m timeout スリープする秒数を指定します。この場合はシグナルを受け取
らなかった場合でも指定した秒数が経過するとスリープを終了
します。省略するとスリープし続けます。

@see Thread::ConditionVariable#...
...signal, Thread::ConditionVariable#broadcast...
...mutex のロックを解放し、カレントスレッドを停止します。
Thread
::ConditionVariable#signalまたは、
Thread
::ConditionVariable#broadcastで送られたシグナルを
受け取ると、mutexのロックを取得し、実行状態となります。

@param mutex Mutex オブ...

Thread::ConditionVariable#broadcast -> self (12150.0)

状態変数を待っているスレッドをすべて再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...スレッドは Thread::ConditionVariable#wait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//emlist[例][ruby]{
mutex = Mutex.new
cv = ConditionVariable.new
flg = true

3.times {
Thread
.start {
mutex.synchronize {
puts "a1"
while (...
...flg)
cv.wait(mutex)
end
puts "a2"
}
}
}

Thread
.start {
mutex.synchronize {
flg = false
cv.broadcast
}
}

sleep 1

# => a1
# => a1
# => a1
# => a2
# => a2
# => a2
//}...

Thread::ConditionVariable.new -> Thread::ConditionVariable (9302.0)

状態変数を生成して返します。

状態変数を生成して返します。

絞り込み条件を変える

Thread::ConditionVariable#signal -> self (9050.0)

状態変数を待っているスレッドを1つ再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...スレッドは Thread::ConditionVariable#wait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//emlist[例][ruby]{
mutex = Mutex.new
cv = ConditionVariable.new
flg = true

3.times {
Thread
.start {
mutex.synchronize {
puts "a1"
while (...
...flg)
cv.wait(mutex)
end
puts "a2"
}
}
}

Thread
.start {
mutex.synchronize {
flg = false
cv.signal
}
}

sleep 1

# => a1
# => a1
# => a1
# => a2
//}...

Monitor#wait_for_cond(cond, timeout) -> bool (6140.0)

MonitorMixin::ConditionVariable 用の内部メソッドです。

...MonitorMixin::ConditionVariable 用の内部メソッドです。

@param cond Thread::ConditionVariable を指定します。
@param timeout タイムアウトまでの秒数。指定しなかった場合はタイムアウトしません。

@return タイムアウトしたときは false を返し...
...ます。それ以外は true を返します。

//emlist[例][ruby]{
require 'monitor'
m = Monitor.new
cv = Thread::ConditionVariable.new
m.enter
m.wait_for_cond(cv, 1)
//}...

Monitor#wait_for_cond(cond, timeout) -> true (6140.0)

MonitorMixin::ConditionVariable 用の内部メソッドです。

...MonitorMixin::ConditionVariable 用の内部メソッドです。

@param cond Thread::ConditionVariable を指定します。
@param timeout タイムアウトまでの秒数。指定しなかった場合はタイムアウトしません。

@return Ruby 1.9 の頃からのバグで常に true を...
...返します。(16608)

//emlist[例][ruby]{
require 'monitor'
m = Monitor.new
cv = Thread::ConditionVariable.new
m.enter
m.wait_for_cond(cv, 1)
//}...

monitor (6024.0)

スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。

...じスレッドから何度も lock できる Mutex としての機能も提供します。

モニターとは、一つの Mutex とそれに関連付けられた複数の
条件変数から構成された、スレッドの同期機構です。
Mutex と 条件変数によって同等の機能を...
...していたら ただ yield するだけ (lock/unlockもしない)
* unlock はそのスレッドだけができる

30447 より。

よりプリミティブな同期機構として、
Mutex、Thread::ConditionVariable も参照してください。

=== 参照

* 6829
* 30447
* 30449...
...関連を保証
していることです。

monitor は以下のような Thread::Mutex としての機能も提供します。
* lock の持ち主がスレッドである Mutex / 何度も lock できる Mutex
* lock したスレッドを Mutex 側が覚えていて
* そのスレッド...
...たら ただ yield するだけ (lock/unlockもしない)
* unlock はそのスレッドだけができる

30447 より。

よりプリミティブな同期機構として、
Thread
::Mutex、Thread::ConditionVariable も参照してください。

=== 参照

* 6829
* 30447
* 30449...