るりまサーチ

最速Rubyリファレンスマニュアル検索!
450件ヒット [201-300件を表示] (0.074秒)
トップページ > クラス:Thread[x] > クエリ:Thread.new[x] > クエリ:run[x] > クエリ:to_s[x]

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

ライブラリ

検索結果

<< < 1 2 3 4 5 > >>

Thread#abort_on_exception -> bool (21059.0)

真の場合、そのスレッドが例外によって終了した時に、インタプリタ 全体を中断させます。false の場合、あるスレッドで起こった例 外は、Thread#join などで検出されない限りそのスレッ ドだけをなにも警告を出さずに終了させます。

...スレッドで起こった例
外は、Thread#join などで検出されない限りそのスレッ
ドだけをなにも警告を出さずに終了させます。

デフォルトは偽です。c:Thread#exceptionを参照してください。

@param newstate 自身を実行中に例外発生し...
...た場合、インタプリタ全体を終了させるかどうかを true か false で指定します。

//emlist[例][ruby]{
thread
= Thread.new { sleep 1 }
thread
.abort_on_exception # => false
thread
.abort_on_exception = true
thread
.abort_on_exception # => true
//}...

Thread#value -> object (21059.0)

スレッド self が終了するまで待ち(Thread#join と同じ)、 そのスレッドのブロックが返した値を返します。スレッド実行中に例外が 発生した場合には、その例外を再発生させます。

...ッド self が終了するまで待ち(Thread#join と同じ)、
そのスレッドのブロックが返した値を返します。スレッド実行中に例外が
発生した場合には、その例外を再発生させます。

スレッドが Thread#kill によって終了した場合は、...
...の終了を待ち結果を出力する例です。

thread
s = []
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| p t.value}

最後の行で、待ち合...
...わせを行っていることがわかりにくいと思うなら以下
のように書くこともできます。

thread
s.each {|t| p t.join.value}...

Thread#run -> self (21047.0)

停止状態(stop)のスレッドを再開させます。 Thread#wakeup と異なりすぐにスレッドの切り替え を行います。

...レッドを再開させます。
Thread
#wakeup と異なりすぐにスレッドの切り替え
を行います。

@raise ThreadError 死んでいるスレッドに対して実行すると発生します。

//emlist[例][ruby]{
a = Thread.new { puts "a"; Thread.stop; puts "c" }
sleep 0.1 while a....
...status!='sleep'
puts "Got here"
a.run
a.join
# => a
# => Got here
# => c
//}

@see Thread#wakeup, Thread.stop...

Thread.stop -> nil (21047.0)

他のスレッドから Thread#run メソッドで再起動されるまで、カレ ントスレッドの実行を停止します。

...ドから Thread#run メソッドで再起動されるまで、カレ
ントスレッドの実行を停止します。

//emlist[例][ruby]{
a = Thread.new { print "a"; Thread.stop; print "c" }
sleep 0.1 while a.status!='sleep'
print "b"
a.run
a.join
# => "abc"
//}

@see Thread#run, Thread#wakeup...

Thread#inspect -> String (21044.0)

自身を人間が読める形式に変換した文字列を返します。

...自身を人間が読める形式に変換した文字列を返します。

//emlist[例][ruby]{
a = Thread.current
a.inspect # => "#<Thread:0x00007fdbaf07ddb0 run>"
b = Thread.new{}
b.inspect # => "#<Thread:0x00007fdbaf8f7d10@(irb):3 dead>"
//}...

絞り込み条件を変える

Thread#alive? -> bool (21043.0)

スレッドが「生きている」時、true を返します。

...」時、true を返します。

例:
thr = Thread.new { }
thr.join # => #<Thread:0x401b3fb0 dead>
Thread
.current.alive? # => true
thr.alive? # => false

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

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

Thread#set_trace_func(pr) -> Proc | nil (21043.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...
....rb", 4, :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", "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_func Kernel.#set_trace_func...

Thread.report_on_exception -> bool (21043.0)

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

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

デフォルトは false です。

Thread.new
{ 1.times { raise } }

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

#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):...
...スレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレポートを無効化しても
...
...を待つことができなかったりするかもしれません。

スレッドごとに設定する方法は Thread#report_on_exception= を参照してください。

@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false...
...終了した時に、その内容を $stderr に報告します。

デフォルトは true です。

Thread.new
{ 1.times { raise } }

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

#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):...

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

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

...と発生します。

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

@see Thread#[]...

Thread#join -> self (21037.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| t.join}...

絞り込み条件を変える

Thread#join(limit) -> self | nil (21037.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| t.join}...
<< < 1 2 3 4 5 > >>