別のキーワード
種類
- インスタンスメソッド (33)
- クラス (22)
- 文書 (20)
ライブラリ
- ビルトイン (55)
クラス
- Thread (33)
キーワード
- Enumerator (11)
-
NEWS for Ruby 2
. 0 . 0 (11) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) - [] (11)
-
thread
_ variable _ get (11) -
thread
_ variable _ set (11)
検索結果
先頭5件
-
Fiber (38114.0)
-
ノンプリエンプティブな軽量スレッド(以下ファイバーと呼ぶ)を提供します。 他の言語では coroutine あるいは semicoroutine と呼ばれることもあります。 Thread と違いユーザレベルスレッドとして実装されています。
...係を持ちます。Fiber#resume を呼んだファイバーが親になり
呼ばれたファイバーが子になります。親子関係を壊すような遷移(例えば
自分の親の親のファイバーへ切り替えるような処理)はできません。
例外 FiberError が発生しま......す。
できることは
* Fiber#resume により子へコンテキストを切り替える
* Fiber.yield により親へコンテキストを切り替える
の二通りです。この親子関係は一時的なものであり
親ファイバーへコンテキストを切り替えた時点で解......レッド間をまたがるファイバーの切り替えはできません。
例外 FiberError が発生します。
//emlist[例:][ruby]{
f = nil
Thread.new do
f = Fiber.new{}
end.join
f.resume
#=> t.rb:5:in `resume': fiber called across threads (FiberError)
# from t.rb:5:in `<main>'
//}... -
NEWS for Ruby 3
. 0 . 0 (102.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...4
* Fiber
* Fiber.new(blocking: true/false) allows you to create non-blocking execution contexts. 16786
* Fiber#blocking? tells whether the fiber is non-blocking. 16786
* Fiber#backtrace and Fiber#backtrace_locations provide per-fiber backtrace. 16815
* The limitation of Fiber#tran......ule M2; end
C.include M1
M1.include M2
p C.ancestors #=> [C, M1, M2, Object, Kernel, BasicObject]
//}
* Mutex
* `Mutex` is now acquired per-`Fiber` instead of per-`Thread`. This change should be compatible for essentially all usages and avoids blocking when using a scheduler. 16792
* Proc......rations and Fiber.scheduler for accessing the current scheduler. See rdoc-ref:fiber.md for more details about what operations are supported and how to implement the scheduler hooks. 16786
* Fiber.blocking? tells whether the current execution context is blocking. 16786
* Thread#join invokes t... -
NEWS for Ruby 2
. 0 . 0 (60.0) -
NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...ラス: Enumerator::Lazy 遅延列挙用のクラス
* ENV
* ENV.to_h は ENV.to_hash へのエイリアスです
* Fiber
* 非互換: Fiber#resume は Fiber#transfer を呼び出したファイバーを再開できなくなりました
* File
* 拡張: File.fnmatch? は File::F......d at thread
creation. default: 512KB or 1024KB.
* RUBY_FIBER_VM_STACK_SIZE: vm stack size used at fiber creation.
default: 64KB or 128KB.
* RUBY_FIBER_MACHINE_STACK_SIZE: machine stack size used at fiber
creation. default: 256KB or 512KB.
* 追加: RubyVM::DEF......ld backtrace location
information. These are returned by Thread#backtrace_locations and
Kernel#caller_locations
* 非互換: Thread#join, Thread#value は対象のスレッドがメインスレッドか現在のスレッドである場合、
ThreadError を発生させます... -
Thread
# [](name) -> object | nil (42.0) -
name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。
..."C" }
].each do |th|
th.join
puts "#{th.inspect}: #{th[:name]}"
end
# => #<Thread:0x00000002a54220 dead>: A
# => #<Thread:0x00000002a541a8 dead>: B
# => #<Thread:0x00000002a54130 dead>: C
//}
Thread#[] と Thread#[]= を用いたスレッド固有の変数は
Fiber を切り替えると異......数に与えるブロックがFiberを切り替える場合は動的スコープとしては
正しく動作しません。
//emlist[][ruby]{
f = Fiber.new {
meth(1) {
Fiber.yield
}
}
meth(2) {
f.resume
}
f.resume
p Thread.current[:name]
# => nil if fiber-local
# => 2 if thread-local (The......value 2 is leaked to outside of meth method.)
//}
Fiber を切り替えても同じ変数を返したい場合は
Thread#thread_variable_get と Thread#thread_variable_set
を使用してください。
Thread#[]=......value 2 is leaked to outside of meth method.)
//}
Fiber を切り替えても同じ変数を返したい場合は
Thread#thread_variable_get と Thread#thread_variable_set
を使用してください。
@see Thread#fetch, Thread#[]=... -
Thread
# thread _ variable _ get(key) -> object | nil (42.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
...変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["foo"] = "bar" # Fiber ロー......カル
Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Thread.current["foo"], # Fiber ローカル
]
}.resume
}.join.value # => ['bar', nil]
この例の "bar" は Thread#thread_variable_get... -
NEWS for Ruby 2
. 7 . 0 (30.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...止められます。
* 「$,」にnil以外の値を設定すると警告が出るようになりました。 14240
nil以外の時はArray#joinで参照した時も警告が出ます。
この警告は「-W:no-deprecated」オプションで止められます。
* ヒアドキュメ.......lazy.with_index(1) { |it, index| puts "#{index}:#{it}" }.take(3).force
# => 1:a
# 2:b
# 3:c
//}
* Fiber
* 新規メソッド
* Fiber#raiseメソッドが追加され、Fiber#resumeのように
resumeして、さらに例外を発生させます。 10344
* File
*......たC API宣言はANYARGSを使わないように変更されました。
See https://github.com/ruby/ruby/pull/2404
=== 実装の改善
* Fiber
* 以前のスタックキャッシュはファイバープールキャッシュに置き換えまれました。
ファイバープール... -
Enumerator (24.0)
-
each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。
...ての機能は Fiber を用いて実装されているため Fiber と同じ制限があります。
例えば以下のようなスレッドをまたいだ呼び出しはエラーになります。
//emlist[例][ruby]{
a = nil
Thread.new do
a = [1, 2, 3].each
a.next
end.join
p a.next
#=> t.rb......:7:in `next': fiber called across threads (FiberError)
# from t.rb:7:in `<main>'
//}... -
Thread
# thread _ variable _ set(key , value) (18.0) -
引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。
...カル変数に引数 value をセットしま
す。
[注意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく
ださい。
//emlist[例][ruby]{
thr = Thread.new do...