種類
- インスタンスメソッド (89)
- 文書 (59)
- クラス (22)
- 特異メソッド (18)
- モジュール (11)
クラス
- Monitor (5)
-
Thread
:: ConditionVariable (22) -
Thread
:: Queue (20) - ThreadsWait (60)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - ConditionVariable (11)
- Monitor (11)
- MonitorMixin (11)
-
NEWS for Ruby 2
. 0 . 0 (11) -
NEWS for Ruby 2
. 2 . 0 (10) -
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 3
. 0 . 0 (4) -
NEWS for Ruby 3
. 1 . 0 (3) -
all
_ waits (18) - broadcast (11)
- close (9)
- empty? (6)
- finished? (6)
- join (6)
-
join
_ nowait (6) -
next
_ wait (6) -
num
_ waiting (11) -
ruby 1
. 8 . 4 feature (11) - signal (11)
- threads (6)
-
wait
_ for _ cond (5)
検索結果
先頭5件
-
ThreadsWait
. new(*threads) -> ThreadsWait (24485.0) -
指定されたスレッドの終了をまつための、スレッド同期オブジェクトをつくります。
...ります。
@param threads 終了を待つスレッドを一つもしくは複数指定します。
使用例
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
thall.all_waits{|th|
printf("end......#=> #<Thread:0x214bc run>
#=> #<Thread:0x21548 run>
#=> #<Thread:0x215d4 run>
#=> #<Thread:0x21660 run>
#=> #<Thread:0x21430 run>
#=> end #<Thread:0x214bc dead>
#=> end #<Thread:0x21548 dead>
#=> end #<Thread:0x215d4 dead>
#=> end #<Thread:0x21660 dead>
#=> end #<Thread:0x21430... -
Thread
:: Queue # num _ waiting -> Integer (17124.0) -
キューを待っているスレッドの数を返します。
...キューを待っているスレッドの数を返します。
//emlist[例][ruby]{
require 'thread'
q = SizedQueue.new(1)
q.push(1)
t = Thread.new { q.push(2) }
sleep 0.05 until t.stop?
q.num_waiting # => 1
q.pop
t.join
//}... -
ThreadsWait
. all _ waits(*threads) {|thread| . . . } -> () (12379.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...クを評価します。
@param threads 終了するまでまつスレッドを一つもしくは複数指定します。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
ThreadsWait.all_waits(*threads) {|th| printf("end %s\n", th.insp......#<Thread:0x21584 run>
#=> #<Thread:0x21610 run>
#=> #<Thread:0x2169c run>
#=> #<Thread:0x21728 run>
#=> #<Thread:0x214f8 run>
#=> end #<Thread:0x21584 dead>
#=> end #<Thread:0x21610 dead>
#=> end #<Thread:0x2169c dead>
#=> end #<Thread:0x21728 dead>
#=> end #<Thread:0x214f8 dead>... -
ThreadsWait
. all _ waits(*threads) -> () (12279.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...クを評価します。
@param threads 終了するまでまつスレッドを一つもしくは複数指定します。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
ThreadsWait.all_waits(*threads) {|th| printf("end %s\n", th.insp......#<Thread:0x21584 run>
#=> #<Thread:0x21610 run>
#=> #<Thread:0x2169c run>
#=> #<Thread:0x21728 run>
#=> #<Thread:0x214f8 run>
#=> end #<Thread:0x21584 dead>
#=> end #<Thread:0x21610 dead>
#=> end #<Thread:0x2169c dead>
#=> end #<Thread:0x21728 dead>
#=> end #<Thread:0x214f8 dead>... -
ThreadsWait
# join _ nowait(*threads) -> () (12254.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。 しかし、実際には終了をまちません。
...threads で指定されたスレッドを指定します。
しかし、実際には終了をまちません。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { s......leep 1; p Thread.current }
}
thall = ThreadsWait.new
p thall.threads #=> []
thall.join_nowait(*threads)
p thall.threads #=> [#<Thread:0x21638 sleep>, #<Thread:0x215ac sleep>, #<Thread:0x21520 sleep>, #<Thread:0x21494 sleep>, #<Thread:0x21408 sleep>]
# 実際には終了を待ってい... -
ThreadsWait
# next _ wait(nonblock = nil) -> Thread (12226.0) -
指定したスレッドのどれかが終了するまで待ちます。
...外 ThreadsWait::ErrNoFinishedThread が発生します。
@raise ErrNoWaitingThread 終了をまつスレッドが存在しない時、発生します。
@raise ErrNoFinishedThread nonblock がtrue でかつ、キューが空の時、発生します。
#使用例
require 'thwait'
threads......= []
2.times {|i|
threads << Thread.new { sleep i }
}
thall = ThreadsWait.new
thall.join_nowait(*threads)
until thall.empty?
th = thall.next_wait
p th
end
@see Queue#pop... -
ThreadsWait
# all _ waits -> () (12184.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...uire 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
thall.all_waits{|th|
printf("end %s\n", th.inspect)
}
# 出力例
#=> #<Thread:0x214bc run>
#=> #<Thread:0x21548 run>
#=> #<Thread:0x215d......4 run>
#=> #<Thread:0x21660 run>
#=> #<Thread:0x21430 run>
#=> end #<Thread:0x214bc dead>
#=> end #<Thread:0x21548 dead>
#=> end #<Thread:0x215d4 dead>
#=> end #<Thread:0x21660 dead>
#=> end #<Thread:0x21430 dead>... -
ThreadsWait
# threads -> Array (12142.0) -
同期されるスレッドの一覧を配列で返します。
...ドの一覧を配列で返します。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
p thall.threads
#=> [#<Thread:0x21750 sleep>, #<Thread:0x216c4 sleep>, #<Thread:0x21638 sleep>]... -
Thread
:: ConditionVariable (11108.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...クラスです。
以下も ConditionVariable を理解するのに参考になります。
https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF
=== Condition Variable とは
あるスレッド A が排他領域で動いていたとします。スレッド A は現在空いてい......れるまで wait メソッドで
スレッドを止めます。他のスレッド b において条件が満たされたなら signal
メソッドでスレッド a に対して条件が成立したことを通知します。これが典型的な
使用例です。
mutex = Mutex.new
cv = Co......nditionVariable.new
a = Thread.start {
mutex.synchronize {
...
while (条件が満たされない)
cv.wait(mutex)
end
...
}
}
b = Thread.start {
mutex.synchronize {
# 上の条件を満たすための... -
Thread
:: ConditionVariable # broadcast -> self (11062.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 (11062.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
:: Queue # num _ waiting -> Integer (9124.0) -
キューを待っているスレッドの数を返します。
...キューを待っているスレッドの数を返します。
//emlist[例][ruby]{
require 'thread'
q = SizedQueue.new(1)
q.push(1)
t = Thread.new { q.push(2) }
sleep 0.05 until t.stop?
q.num_waiting # => 1
q.pop
t.join
//}... -
NEWS for Ruby 2
. 0 . 0 (6198.0) -
NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 2.0.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......utex#try_lock, Mutex#synchronize, Mutex#sleep
はトラップハンドラの中では使えなくなりました。そのようなときは ThreadError が発生します
* Mutex#sleep may spurious wakeup. Check after wakeup.
* NilClass
* 追加: NilClass#to_h 空のハッシュ......。
* io/wait
* 追加: IO#wait_writable
* 追加: IO#wait_readable は IO#wait の別名です。
* json
* 1.7.7 に更新
* net/http
* 新機能
* Proxies are now automatically detected from the http_proxy environment
variable. See Net::HTTP.new for details.... -
NEWS for Ruby 3
. 1 . 0 (6150.0) -
NEWS for Ruby 3.1.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 3.1.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......4
* Thread
* 新規メソッド
* Thread#native_thread_id が追加されました。 17853
* Thread::Backtrace
* 新規メソッド
* --backtrace-limit コマンドラインオプションで設定したバックトレースの長さを制限する値を返す Thread::Back......18020
* IOフックのio_wait、io_read、io_writeは、可能ならばオリジナルのIOオブジェクトを受け取るようになりました。 18003
* MonitorがFiberセーフになりました。 17827
* コピーコルーチンをpthread実装に置き換えました。... -
ThreadsWait
# join(*threads) -> () (6148.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。
...threads で指定されたスレッドを指定します。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWai......t.new
p thall.threads #=> []
thall.join(*threads)
p thall.threads
#=> [#<Thread:0x216ec dead>, #<Thread:0x21660 dead>, #<Thread:0x215d4 dead>, #<Thread:0x214bc dead>]... -
Monitor
# wait _ for _ cond(cond , timeout) -> bool (6131.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 (6131.0) -
MonitorMixin::ConditionVariable 用の内部メソッドです。
...d 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 3
. 0 . 0 (6120.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 3.0.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......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 sort the results by def......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... -
NEWS for Ruby 2
. 2 . 0 (6090.0) -
NEWS for Ruby 2.2.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 2.2.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス.......
* rb_thread_blocking_region_begin -> rb_thread_call_without_gvl family
* rb_thread_blocking_region_end -> rb_thread_call_without_gvl family
* TRAP_BEG -> rb_thread_call_without_gvl family
* TRAP_END -> rb_thread_call_without_gvl family
* rb_thread_select -> rb_thread_fd_select......nction. no replacement.
* rb_run_exec_options_err : internal function. no replacement.
* rb_thread_blocking_region -> rb_thread_call_without_gvl family
* rb_thread_polling -> rb_thread_wait_for
* rb_big2str0 : internal function. no replacement.
* rb_big2ulong_pack -> rb_integer_p... -
NEWS for Ruby 2
. 3 . 0 (6066.0) -
NEWS for Ruby 2.3.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...NEWS for Ruby 2.3.0
このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
それぞれのエントリーは参照情報があるため短いです。
十分な情報と共に書かれた全ての変更のリス......t show each method (show block lines directly).
TracePoint also ignores these calls.
11569
* Queue (Thread::Queue)
* 終了を通知するために Queue#close(Thread::Queue#close) を追加
10600
* Regexp/String: Unicode のバージョンを 7.0.0 から 8.0.0 に更新......しません)
11695
* ログデバイスを開きなおすために Logger#reopen が追加されました。
11696
* io/wait
* IO#wait_readable は FIONREAD をチェックしなくなりました。
ソケットのようなバイトストリームではないIOで使...