22件ヒット
[1-22件を表示]
(0.034秒)
別のキーワード
ライブラリ
- ビルトイン (9)
- continuation (11)
- thread (2)
キーワード
- ConditionVariable (11)
- Continuation (11)
検索結果
-
Thread
:: ConditionVariable (6031.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...の一つである状態変数を実現するクラスです。
以下も ConditionVariable を理解するのに参考になります。
https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF
=== Condition Variable とは
あるスレッド A が排他領域で動いていたとし......リソースの空きを
待っていても、いつまでも空くことはありません。
以上のような状況を解決するのが Condition Variable です。
スレッド a で条件(リソースが空いているかなど)が満たされるまで wait メソッドで
スレッドを......、
あるいは満タンになった場合に Condition Variable を使って wait しています。
require 'thread'
class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex = Mutex.new
@q = []... -
Continuation (6013.0)
-
継続を表すクラスです。
...cont は、Continuation クラスのインスタ
ンスで、Continuation#call メソッドを実行するこ
とでいつでも記憶した状態を継続することができます。
C 言語の setjmp()/longjmp() がわかる人は
setjmp() == callcc {|c| }
longjmp() == c.call
と考えれ......いう違いがあります)
callcc() は、ブロックの戻り値を返しますが、Continuation#call(args)
が呼び出されたときは args を返します。
例:
以下は、Continuationによる無限ループの例
def LOOP
c = nil
yield callcc {|cnt| c = cnt; true }......c.call(false)
end
LOOP {|v| p v}
=> true
false
false
false
:
:
callcc とは、call-with-current-continuation の略です。...