るりまサーチ

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

別のキーワード

  1. drb thread
  2. thread pending_interrupt?
  3. thread join
  4. thread kill
  5. thread exit

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

ConditionVariable (46032.0)

Alias of Thread::ConditionVariable

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

Thread::ConditionVariable (29054.0)

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

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

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

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

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとしま...
...リソースの空きを
待っていても、いつまでも空くことはありません。

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

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

mutex = Mutex.new
cv = ConditionVariable.new

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

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

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

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

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

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

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

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

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

@see Thread::ConditionVariable#signal, Thread::ConditionVariable#broadcast...

Thread::ConditionVariable#broadcast -> self (14050.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 {
pu...
...ts "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#signal -> self (14050.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 {
pu...
...ts "a1"
while (flg)
cv.wait(mutex)
end
puts "a2"
}
}
}

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

sleep 1

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

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

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

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

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

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

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

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

@see Thread::ConditionVariable#signal, Thread::ConditionVariable#broadcast...

Thread::ConditionVariable#broadcast -> self (6050.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 {
pu...
...ts "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#signal -> self (6050.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 {
pu...
...ts "a1"
while (flg)
cv.wait(mutex)
end
puts "a2"
}
}
}

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

sleep 1

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

絞り込み条件を変える

NEWS for Ruby 3.0.0 (42.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...val when called with one argument will use `"(eval)"` for `__FILE__` and `1` for `__LINE__` in the evaluated code. 4352 17419
* ConditionVariable
* ConditionVariable#wait may now invoke the `block`/`unblock` scheduler hooks in a non-blocking context. 16786
* Dir
* Dir.glob and Dir.[] now...
...M1.include M2
p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
//}

* Mutex
* `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change should be compatible for essentially all usages and avoids blocking when using a scheduler. 16792
* Proc
* Proc#== and Proc#eq...
...* Fiber.blocking? tells whether the current execution context is blocking. 16786
* Thread#join invokes the scheduler hooks `block`/`unblock` in a non-blocking execution context. 16786
* Thread
* Thread.ignore_deadlock accessor has been added for disabling the default deadlock detection,...

Monitor#wait_for_cond(cond, timeout) -> bool (40.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 (40.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)
//}...

NEWS for Ruby 2.5.0 (36.0)

NEWS for Ruby 2.5.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...323

* IOError
* IO#close 以前は"stream closed"というメッセージの例外が発生していましたが、"stream closed in another thread"というメッセージに改良しました。
このメッセージはユーザーにとってわかりやすいでしょう。 13405...
...のバージョンを 9.0.0 から 10.0.0 に更新しました。 13685

* Thread
* Thread#name= で設定した名前が Windows 10 で見えるようになりました
* Thread#fetch を追加 13009
* Thread.report_on_exception のデフォルト値がtrueになりました。...
...しました。
シードを必要としない用途で有用です。9569

* Socket
* Socket::Ifaddr#vhid を追加 13803

* ConditionVariable, Queue, SizedQueue を速度向上のため再実装しました。
これらのクラスはStructのサブクラスではなくなりま...

monitor (24.0)

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

...ことは
可能ですが、モニタの利点はライブラリがその関連を保証
していることです。

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

30447 より。

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

=== 参照

* 6829
* 30447
* 30449...

絞り込み条件を変える

<< 1 2 > >>