るりまサーチ

最速Rubyリファレンスマニュアル検索!
462件ヒット [201-300件を表示] (0.126秒)

別のキーワード

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

ライブラリ

モジュール

キーワード

検索結果

<< < 1 2 3 4 5 > >>

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

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

...@param name スレッド固有データのキーを文字列か Symbol で指定します。

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

# => #<Thread:0x00000002a54220 dead>: A
# => #<Thread:0x00000002a541a8 dead>: B
# => #<Thread:0x00000002a54130 dead>: C
//}

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

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

この関数に与えるブロックがFiberを切り替える場合は動的スコープとしては...

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

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

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

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

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

@raise ThreadError 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 = rand(5); sleep n; n })

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

Thread#raise(error_type, message, traceback) -> () (12131.0)

自身が表すスレッドで強制的に例外を発生させます。

...に例外を発生させます。

@param error_type Kernel.#raise を参照してください。

@param message Kernel.#raise を参照してください。

@param traceback Kernel.#raise を参照してください。

Thread
.new {
sleep 1
Thread
.main.raise "foobar"
}

begin
sl...
...eep
rescue
p $!, $@
end

=> #<RuntimeError: foobar>
["-:3"]...

Thread#join -> self (12037.0)

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

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

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

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

@raise ThreadError 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 = rand(5); sleep n; n })

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

Thread#[]=(name,val) (12019.0)

val を name に対応するスレッド固有のデータとして格納します。

...ッド固有のデータとして格納します。

@param name スレッド固有データのキーを文字列か Symbol で指定します。文字列を指定した場合は String#to_sym によりシンボルに変換されます。

@param val スレッド固有データを指定します。n...
...il を指定するとそのスレッド固有データは削除されます。


@see Thread#[]...

絞り込み条件を変える

Thread#key?(name) -> bool (12013.0)

name に対応したスレッドに固有のデータが定義されていれば true を返します。

...name に対応したスレッドに固有のデータが定義されていれば
t
rue を返します。

@param name 文字列か Symbol で指定します。

//emlist[例][ruby]{
me = Thread.current
me[:oliver] = "a"
me.key?(:oliver) # => true
me.key?(:stanley) # => false
//}...

ThreadsWait#join_nowait(*threads) -> () (9249.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>]
# 実際には終了を待って...

ThreadsWait#next_wait(nonblock = nil) -> Thread (9214.0)

指定したスレッドのどれかが終了するまで待ちます。

...待ちます。

@param nonblock true を与えると、キューが空の時、例外 ThreadsWait::ErrNoFinishedThread が発生します。

@raise ErrNoWaitingThread 終了をまつスレッドが存在しない時、発生します。

@raise ErrNoFinishedThread nonblock がtrue でかつ、キ...
...ューが空の時、発生します。

#使用例
require 'thwait'

thread
s = []
2.times {|i|
thread
s << Thread.new { sleep i }
}

t
hall = ThreadsWait.new
t
hall.join_nowait(*threads)
until thall.empty?
t
h = thall.next_wait
p th
end

@see Queue#pop...

Thread::ConditionVariable#wait(mutex, timeout = nil) -> self (9157.0)

mutex のロックを解放し、カレントスレッドを停止します。 Thread::ConditionVariable#signalまたは、 Thread::ConditionVariable#broadcastで送られたシグナルを 受け取ると、mutexのロックを取得し、実行状態となります。

...mutex のロックを解放し、カレントスレッドを停止します。
Thread
::ConditionVariable#signalまたは、
Thread
::ConditionVariable#broadcastで送られたシグナルを
受け取ると、mutexのロックを取得し、実行状態となります。

@param mutex Mutex オブ...
...@param timeout スリープする秒数を指定します。この場合はシグナルを受け取
らなかった場合でも指定した秒数が経過するとスリープを終了
します。省略するとスリープし続けます。

@see Thread::ConditionVa...
...riable#signal, Thread::ConditionVariable#broadcast...

Thread::SizedQueue#shift(non_block = false) -> object (9137.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...
...ush(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 (9131.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, :resource2...
...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"
//}...
<< < 1 2 3 4 5 > >>