クラス
- Exception (11)
- Fiber (14)
- IO (110)
- Mutex (10)
- Thread (610)
-
Thread
:: Backtrace :: Location (77) -
Thread
:: ConditionVariable (36) -
Thread
:: Mutex (72) -
Thread
:: Queue (129) -
Thread
:: SizedQueue (111) - ThreadGroup (66)
- TracePoint (11)
キーワード
-
$ -d (11) -
$ DEBUG (11) -
$ SAFE (7) - << (18)
-
CLOCK
_ THREAD _ CPUTIME _ ID (11) - ClosedQueueError (9)
- ConditionVariable (18)
- DEBUG (11)
- DEBUG= (11)
- Default (11)
- Enumerator (11)
- Fiber (11)
- Location (11)
-
MUTEX
_ FOR _ THREAD _ EXCLUSIVE (5) - Mutex (18)
- Queue (18)
- SizedQueue (18)
- ThreadError (11)
- ThreadGroup (11)
- [] (11)
- []= (11)
-
abort
_ on _ exception (22) -
abort
_ on _ exception= (22) -
absolute
_ path (11) - add (11)
-
add
_ trace _ func (11) - alive? (11)
- backtrace (11)
-
backtrace
_ locations (33) -
base
_ label (11) - broadcast (9)
-
caller
_ locations (22) - clear (9)
-
clock
_ gettime (11) - close (18)
- closed? (9)
- current (11)
- deq (18)
- detach (11)
- empty? (16)
- enclose (11)
- enclosed? (11)
- enq (18)
- eof (11)
- eof? (11)
- exclusive (11)
- exit (22)
- fetch (7)
- fork (11)
- group (11)
-
handle
_ interrupt (11) -
ignore
_ deadlock (3) -
ignore
_ deadlock= (3) - inspect (22)
- join (22)
- key? (11)
- keys (11)
- kill (22)
- label (11)
- length (16)
- lineno (11)
- list (22)
- lock (11)
- locked? (9)
- main (11)
- max (9)
- max= (9)
- name (9)
- name= (9)
- new (74)
-
num
_ waiting (9) - owned? (11)
- pass (11)
- path (11)
-
pending
_ interrupt? (22) - pipe (88)
- pop (18)
- priority (11)
- priority= (11)
- push (18)
- raise (11)
-
report
_ on _ exception (16) -
report
_ on _ exception= (16) - resume (11)
- run (11)
-
safe
_ level (7) -
set
_ trace _ func (11) - shift (18)
- signal (9)
- size (16)
- sleep (33)
- start (11)
- status (11)
- stop (11)
- stop? (11)
- synchronize (9)
- terminate (11)
-
thread
_ variable? (11) -
thread
_ variable _ get (11) -
thread
_ variable _ set (11) -
to
_ s (18) - transfer (3)
-
try
_ lock (9) - unlock (11)
- value (11)
- wait (9)
- wakeup (11)
検索結果
先頭5件
-
Thread (52114.0)
-
スレッドを表すクラスです。スレッドとはメモリ空間を共有して同時に実行される制御の流れです。 Thread を使うことで並行プログラミングが可能になります。
...スレッドを表すクラスです。スレッドとはメモリ空間を共有して同時に実行される制御の流れです。
Thread を使うことで並行プログラミングが可能になります。
=== 実装
ネイティブスレッドを用いて実装されていますが、......了は正常な終了も例外などによる異常終了も含みます。
===[a:exception] 例外発生時のスレッドの振る舞い
あるスレッドで例外が発生し、そのスレッド内で rescue で捕捉されなかっ
た場合、通常はそのスレッドだけがなにも警......を Thread#join で待っている他の
スレッドがある場合、その待っているスレッドに対して、同じ例外が再度
発生します。
begin
t = Thread.new do
Thread.pass # メインスレッドが確実にjoinするように
raise "unhandled exception"... -
Thread
:: MUTEX _ FOR _ THREAD _ EXCLUSIVE -> Mutex (47419.0) -
Thread.exclusive用のMutexオブジェクトです。
...
Thread.exclusive用のMutexオブジェクトです。......
Thread.exclusive用のMutexオブジェクトです。
(private constant です。)... -
Thread
# thread _ variable _ get(key) -> object | nil (44287.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
...key で指定した名前のスレッドローカル変数を返します。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
Thread.current.......thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"] = "bar" # Fiber ローカル
Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Thread.current["foo"],......# Fiber ローカル
]
}.resume
}.join.value # => ['bar', nil]
この例の "bar" は Thread#thread_variable_get により得られ
た値で、nil はThread#[] により得られた値です。
@see Thread#thread_variable_set, Thread#[]
@see https://magazine.rubyist.net/articles/00... -
Thread
# thread _ variable _ set(key , value) (44269.0) -
引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。
...引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま
す。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく......。
//emlist[例][ruby]{
thr = Thread.new do
Thread.current.thread_variable_set(:cat, 'meow')
Thread.current.thread_variable_set("dog", 'woof')
end
thr.join # => #<Thread:0x401b3f10 dead>
thr.thread_variables # => [:dog, :cat]
//}
@see Thread#thread_variable_get, Thread#[]... -
Thread
# thread _ variable?(key) -> bool (44251.0) -
引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。
...key で指定した名前のスレッドローカル変数が存在する場合に true、そ
うでない場合に false を返します。
@param key 変数名を String か Symbol で指定します。
me = Thread.current
me.thread_variable_set(:oliver, "a")
me.thread_variable?(:oliver......) # => true
me.thread_variable?(:stanley) # => false
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)が
対象ではない事に注意してください。
@see Thread#thread_variable_get, Thread#[]... -
Thread
# report _ on _ exception -> bool (38256.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...derr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Thread......; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x00......007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# report _ on _ exception=(newstate) (38256.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...derr に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Thread......; raise }
a.report_on_exception = true
a.report_on_exception # => true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x00......007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
. report _ on _ exception -> bool (38250.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレ......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
. report _ on _ exception=(newstate) (38250.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレ......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
# ignore _ deadlock=(bool) (38120.0) -
デッドロック検知を無視する機能をon/offします。デフォルト値はfalseです。
...seです。
trueを渡すとデッドロックを検知しなくなります。
//emlist[][ruby]{
Thread.ignore_deadlock = true
queue = Thread::Queue.new
trap(:SIGUSR1){queue.push "Received signal"}
# ignore_deadlockがfalseだとエラーが発生する
puts queue.pop
//}
@see Thread#ignore_de... -
Thread
# ignore _ deadlock -> bool (38108.0) -
デッドロック検知を無視する機能のon/offを返します。
...デッドロック検知を無視する機能のon/offを返します。
デフォルト値はfalseで、デッドロックが検知されます。
@see Thread#ignore_deadlock=... -
Thread
# backtrace _ locations(range) -> [Thread :: Backtrace :: Location] | nil (35250.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...クトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得する......range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_loca......tions # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test.rb:1:in `block in <main>'"]
//}
@see Thread::Backtrace::Location... -
Thread
# backtrace _ locations(start = 0 , length = nil) -> [Thread :: Backtrace :: Location] | nil (35250.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...クトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得する......range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_loca......tions # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test.rb:1:in `block in <main>'"]
//}
@see Thread::Backtrace::Location...