るりまサーチ (Ruby 2.5.0)

最速Rubyリファレンスマニュアル検索!
1件ヒット [1-1件を表示] (0.008秒)
トップページ > バージョン:2.5.0[x] > クエリ:Module[x] > ライブラリ:monitor[x]

別のキーワード

  1. module attr
  2. module new
  3. erb def_module
  4. module constants
  5. module module_eval

検索結果

MonitorMixin (43.0)

スレッドの同期機構としてのモニター機能を提供するモジュールです。

.../オブジェクトに
モニタ機能を追加します。

=== 例

//emlist[消費者、生産者問題の例][ruby]{
require 'monitor'

buf = []
buf.extend(MonitorMixin) # 配列にモニタ機能を追加
empty_cond = buf.new_cond # 配列が空であるかないかを通知する条件変数...
...= 初期化

Monitor
Mixin は初期化される必要があります。
上の例のように Object#extend を使って利用する場合は
自動的に初期化されます。

//emlist[extend する例][ruby]{
require 'monitor'
buf = []
buf.extend(MonitorMixin)
//}

しかし、MonitorMixin を...
...け付けないので
super ではなく super() を呼ぶ必要があります。

//emlist[include する例][ruby]{
require 'monitor'

class MyObject
include MonitorMixin

def initialize(val)
super()
@value = val
end

def to_s
synchronize {
@value.to_s
}
end
end
//...