るりまサーチ

最速Rubyリファレンスマニュアル検索!
254件ヒット [1-100件を表示] (0.121秒)

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

<< 1 2 3 > >>

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

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

...に対して発生します。

limit を指定して、limit 秒過ぎても自身が終了しない場合、nil を返します。

@
param limit タイムアウトする時間を整数か小数で指定します。単位は秒です。

@
raise ThreadError join を実行することによってデ...
...レッドを join したときにも発生します。

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

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 = ran...
...d(5); sleep n; n })

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

Thread#join -> self (30163.0)

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

...に対して発生します。

limit を指定して、limit 秒過ぎても自身が終了しない場合、nil を返します。

@
param limit タイムアウトする時間を整数か小数で指定します。単位は秒です。

@
raise ThreadError join を実行することによってデ...
...レッドを join したときにも発生します。

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

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 = ran...
...d(5); sleep n; n })

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

ThreadsWait#join(*threads) -> () (24350.0)

終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。

...threads で指定されたスレッドを指定します。

@
param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。

require 'thwait'

thread
s = []
5.times {|i|
thread
s << Thread.new { sleep 1; p Thread.current }
}

t
hall = ThreadsWai...
...t.new
p thall.threads #=> []
t
hall.join(*threads)
p thall.threads
#=> [#<Thread:0x216ec dead>, #<Thread:0x21660 dead>, #<Thread:0x215d4 dead>, #<Thread:0x214bc dead>]...

Thread#thread_variable_get(key) -> object | nil (24304.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) (24280.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::SizedQueue#shift(non_block = false) -> object (17155.0)

キューからひとつ値を取り出します。 キューに push しようと待っているスレッドがあれば、実行を再開させます。

...ば、実行を再開させます。

@
param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = SizedQueue.new(4)

t
h1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :reso...
...r)
}

t
h1.join
# => resource1
# resource2
# resource3
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = SizedQueue.new(4)

t
h1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resource2, :resource3, nil].each{|r|
q.push(r)
}

begin
t
h1.join
q...
....pop(true)
rescue => e
p e
p e.message
end

# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}

@
see Thread::Queue#pop...

Thread::Queue#shift(non_block = false) -> object (17143.0)

キューからひとつ値を取り出します。キューが空の時、呼出元のスレッドは停止します。

...出元のスレッドは停止します。

@
param non_block true を与えると、キューが空の時に例外 ThreadError が発生します。

//emlist[例][ruby]{
require 'thread'

q = Queue.new

t
h1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resour...
...ch { |r|
q.push(r)
}

t
h1.join
//}

//emlist[例: nonblock = true][ruby]{
require 'thread'

q = Queue.new

t
h1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resource2, :resource3, nil].each { |r|
q.push(r)
}

begin
t
h1.join
q.pop(true)
rescue => e
p...
...e
end

# => resource1
# resource2
# resource3
# => #<ThreadError: queue empty>
# => "queue empty"
//}...

ThreadsWait#join_nowait(*threads) -> () (15356.0)

終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。 しかし、実際には終了をまちません。

...threads で指定されたスレッドを指定します。
しかし、実際には終了をまちません。

@
param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。

require 'thwait'

thread
s = []
5.times {|i|
thread
s << Thread.new...
...{ sleep 1; p Thread.current }
}

t
hall = ThreadsWait.new
p thall.threads #=> []
t
hall.join_nowait(*threads)
p thall.threads #=> [#<Thread:0x21638 sleep>, #<Thread:0x215ac sleep>, #<Thread:0x21520 sleep>, #<Thread:0x21494 sleep>, #<Thread:0x21408 sleep>]
# 実際には終了を待って...

Thread#abort_on_exception -> bool (15175.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#abort_on_exception=(newstate) (15175.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#fetch(name, default = nil) {|name| ... } -> object (15161.0)

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

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

@
param name スレッド固有データのキーを文字列か Symbol で指定します。
@
param default name に対応するスレ...
...す。
@
raise KeyError 引数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#set_trace_func(pr) -> Proc | nil (15155.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...
<< 1 2 3 > >>