るりまサーチ

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

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. zlib end

ライブラリ

キーワード

検索結果

<< 1 2 3 > >>

Thread.pending_interrupt?(error = nil) -> bool (6125.0)

非同期割り込みのキューが空かどうかを返します。

...します。

Thread
.handle_interrupt は非同期割り込みの発生を延期させるのに使
用しますが、本メソッドは任意の非同期割り込みが存在するかどうかを確認す
るのに使用します。

本メソッドが true を返した場合、Thread.handle_interru...
...させられていた例外をただちに発生させる。

def Thread.kick_interrupt_immediately
Thread
.handle_interrupt(Object => :immediate) {
Thread
.pass
}
end


=== 使い方

th = Thread.new{
Thread
.handle_interrupt(RuntimeError => :on_blocking){
while true...
...if Thread.pending_interrupt?
Thread
.handle_interrupt(Object => :immediate){}
end

...
end

}
}
...
th.raise # スレッド停止。

この例は以下のように記述する事もできます。

flag = true
th = Thread.new{
Thread
.handle_in...

Thread#pending_interrupt?(error = nil) -> bool (6101.0)

self の非同期例外のキューが空かどうかを返します。

...self の非同期例外のキューが空かどうかを返します。

@param error 対象の例外クラスを指定します。


@see Thread.pending_interrupt?...

Thread#[](name) -> object | nil (19.0)

name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。

...emlist[例][ruby]{
[
Thread
.new { Thread.current["name"] = "A" },
Thread
.new { Thread.current[:name] = "B" },
Thread
.new { Thread.current["name"] = "C" }
].each do |th|
th.join
puts "#{th.inspect}: #{th[:name]}"
end


# => #<Thread:0x00000002a54220 dead>: A
# => #<Thread:0x00000002a541a8 d...
...0000002a54130 dead>: C
//}

Thread
#[] と Thread#[]= を用いたスレッド固有の変数は
Fiber を切り替えると異なる変数を返す事に注意してください。

//emlist[][ruby]{
def meth(newvalue)
begin
oldvalue = Thread.current[:name]
Thread
.current[:name] = newvalu...
...ent[:name] = oldvalue
end

end

//}

この関数に与えるブロックがFiberを切り替える場合は動的スコープとしては
正しく動作しません。

//emlist[][ruby]{
f = Fiber.new {
meth(1) {
Fiber.yield
}
}
meth(2) {
f.resume
}
f.resume
p Thread.current[:name]
# =>...

Thread#add_trace_func(pr) -> Proc (19.0)

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

...したハンドラを返します。

@param pr トレースハンドラ(Proc オブジェクト)

//emlist[例][ruby]{
th = Thread.new do
class Trace
end

43.to_s
end

th.add_trace_func lambda {|*arg| p arg }
th.join

# => ["line", "example.rb", 4, nil, #<Binding:0x00007f98e107d0d8>, nil]
# =>...
..., "example.rb", 4, :inherited, #<Binding:0x00007f98e1085d00>, Class]
# => ["class", "example.rb", 4, nil, #<Binding:0x00007f98e108f210>, nil]
# => ["end", "example.rb", 5, nil, #<Binding:0x00007f98e108e5e0>, nil]
# => ["line", "example.rb", 6, nil, #<Binding:0x00007f98e108d4b0>, nil]
# => ["c-call",...
..."example.rb", 6, :to_s, #<Binding:0x00007f98e1097aa0>, Integer]
# => ["c-return", "example.rb", 6, :to_s, #<Binding:0x00007f98e1095cc8>, Integer]
//}

@see Thread#set_trace_func Kernel.#set_trace_func...

Thread#backtrace -> [String] | nil (19.0)

スレッドの現在のバックトレースを返します。

...がすでに終了している場合は nil を返します。

//emlist[例][ruby]{
class C1
def m1
sleep 5
end

def m2
m1
end

end


th = Thread.new {C1.new.m2; Thread.stop}
th.backtrace
# => [
# [0] "(irb):3:in `sleep'",
# [1] "(irb):3:in `m1'",
# [2] "(irb):6:in `m2'"...

絞り込み条件を変える

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

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

...トレースを解除します。

設定したハンドラを返します。

//emlist[例][ruby]{
th = Thread.new do
class Trace
end

2.to_s
Thread
.current.set_trace_func nil
3.to_s
end

th.set_trace_func lambda {|*arg| p arg }
th.join

# => ["line", "example.rb", 2, nil, #<Binding:0x00007...
..., "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, #<Binding:0x00007fc8de88c440>, nil]
# => ["c-call",...
...fc8de967798>, Thread]
# => ["c-return", "example.rb", 5, :current, #<Binding:0x00007fc8de9673b0>, Thread]
# => ["c-call", "example.rb", 5, :set_trace_func, #<Binding:0x00007fc8de966fc8>, Thread]
//}

@param pr トレースハンドラ(Proc オブジェクト) もしくは nil
@see Thread#add_trace_f...

Thread#exit -> self (13.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...レッドの Thread#value の返り値は不定です。
自身がメインスレッドであるか最後のスレッドである場合は、プロセスを Kernel.#exit(0)
により終了します。

Kernel.#exit と違い例外 SystemExit を発生しません。

th1 = Thread.new do
begi...
...n
sleep 10
ensure
p "this will be displayed"
end

end


sleep 0.1
th1.kill

#=> "this will be displayed"

@see Kernel.#exit, Kernel.#exit!...

Thread#kill -> self (13.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...レッドの Thread#value の返り値は不定です。
自身がメインスレッドであるか最後のスレッドである場合は、プロセスを Kernel.#exit(0)
により終了します。

Kernel.#exit と違い例外 SystemExit を発生しません。

th1 = Thread.new do
begi...
...n
sleep 10
ensure
p "this will be displayed"
end

end


sleep 0.1
th1.kill

#=> "this will be displayed"

@see Kernel.#exit, Kernel.#exit!...

Thread#priority -> Integer (13.0)

スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。

...ットフォームに依存します。

//emlist[例][ruby]{
Thread
.current.priority # => 0

count1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end

a.priority = -1

b = Thread.new do
loop { count2 += 1 }
end

b.priority = -2
count1 = count2 = 0 # reset
sleep 1 # => 1...
<< 1 2 3 > >>