るりまサーチ

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

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. t61string new
  4. matrix t
  5. fiddle type_size_t

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

Thread.current -> Thread (45320.0)

現在実行中のスレッド(カレントスレッド)を返します。

...現在実行中のスレッド(カレントスレッド)を返します。

p Thread.current #=> #<Thread:0x4022e6fc run>...

Thread#thread_variable_get(key) -> object | nil (36309.0)

引数 key で指定した名前のスレッドローカル変数を返します。

...]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。

例:

Thread
.new {
Thread
.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread
.current["foo"...
...
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/0041/0041-200Special-note.html...

Thread#thread_variable_set(key, value) (36279.0)

引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。

...]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく
ださい。

//emlist[例][ruby]{
t
hr = Thread.new do
Thread
.current.thread_variable_set(:cat, 'meow')
Thread
.c...
...urrent.thread_variable_set("dog", 'woof')
end
t
hr.join # => #<Thread:0x401b3f10 dead>
t
hr.thread_variables # => [:dog, :cat]
//}

@see Thread#thread_variable_get, Thread#[]...

Thread#thread_variable?(key) -> bool (36255.0)

引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。

... 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#status -> String | false | nil (27172.0)

生きているスレッドの状態を文字列 "run"、"sleep", "aborting" のいず れかで返します。正常終了したスレッドに対して false、例外によ り終了したスレッドに対して nil を返します。

...orting" のいず
れかで返します。正常終了したスレッドに対して false、例外によ
り終了したスレッドに対して nil を返します。

Thread
#alive? が真を返すなら、このメソッドも真です。

例:
a = Thread.new { raise("die now") }
b = Thread.n...
... Thread.stop }
c = Thread.new { Thread.exit }
d = Thread.new { sleep }
d.kill #=> #<Thread:0x401b3678 aborting>
a.status #=> nil
b.status #=> "sleep"
c.status #=> false
d.status #=> "aborting"
Thread
.current...
....status #=> "run"

@see Thread#alive?, Thread#stop?...

絞り込み条件を変える

Thread#set_trace_func(pr) -> Proc | nil (27154.0)

スレッドにトレース用ハンドラを設定します。

...

//emlist[例][ruby]{
t
h = Thread.new do
class Trace
end
2.to_s
Thread
.current.set_trace_func nil
3.to_s
end
t
h.set_trace_func lambda {|*arg| p arg }
t
h.join

# => ["line", "example.rb", 2, nil, #<Binding:0x00007fc8de87cb08>, nil]
# => ["c-call", "example.rb", 2, :inherited, #<Binding:...
...0x00007fc8de886770>, Class]
# => ["c-return", "example.rb", 2, :inherited, #<Binding:0x00007fc8de8844e8>, Class]
# => ["class", "example.rb", 2, nil, #<Binding:0x00007fc8de88e830>, nil]
# => ["end", "example.rb", 3, nil, #<Binding:0x00007fc8de88d6b0>, nil]
# => ["line", "example.rb", 4, nil, #<Bindi...
..., :to_s, #<Binding:0x00007fc8de896f30>, Integer]
# => ["c-return", "example.rb", 4, :to_s, #<Binding:0x00007fc8de894a50>, Integer]
# => ["line", "example.rb", 5, nil, #<Binding:0x00007fc8de967b08>, nil]
# => ["c-call", "example.rb", 5, :current, #<Binding:0x00007fc8de967798>, Thread]
# => ["c-return...

Thread.report_on_exception -> bool (27142.0)

真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。

...、その内容を $stderr に報告します。

デフォルトは false です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...
...-e:1:in `block in <main>'
1: from -e:1:in `times'

これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:...
...が終了しないようにするのがより良い方法です。
* 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):
T
raceback (most recent call last):
2: from...

Thread.report_on_exception=(newstate) (27142.0)

真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。

...、その内容を $stderr に報告します。

デフォルトは false です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...
...-e:1:in `block in <main>'
1: from -e:1:in `times'

これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:...
...が終了しないようにするのがより良い方法です。
* 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):
T
raceback (most recent call last):
2: from...

Thread#fetch(name, default = nil) {|name| ... } -> object (27136.0)

name に関連づけられたスレッドに固有のデータを返します。 name に対応するスレッド固有データがない時には、引数 default が 与えられていればその値を、ブロックが与えられていれば そのブロックを評価した値を返します。

...時には、引数 default
与えられていればその値を、ブロックが与えられていれば
そのブロックを評価した値を返します。

@param name スレッド固有データのキーを文字列か Symbol で指定します。
@param default name に対応するスレ...
...defaultもブロックも与えられてない時、
name に対応するスレッド固有データがないと発生します。

//emlist[例][ruby]{
t
h = Thread.new { Thread.current[:name] = 'A' }
t
h.join
t
h.fetch(:name) # => "A"
t
h.fetch(:fetch, 'B') # => "B"
t
h.fetch('name'...
...) {|name| "Thread" + name} # => "A"
t
h.fetch('fetch') {|name| "Thread" + name} # => "Threadfetch"
//}

@see Thread#[]...

Thread#stop? -> bool (27136.0)

スレッドが終了(dead)あるいは停止(stop)している時、true を返します。

...スレッドが終了(dead)あるいは停止(stop)している時、true を返します。

//emlist[例][ruby]{
a = Thread.new { Thread.stop }
b = Thread.current
a.stop? # => true
b.stop? # => false
//}

@see Thread#alive?, Thread#status...

絞り込み条件を変える

<< 1 2 3 ... > >>