るりまサーチ

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

別のキーワード

  1. mutex_m lock
  2. mutex_m unlock
  3. mutex_m mu_lock
  4. mutex_m locked?
  5. mutex_m try_lock

ライブラリ

クラス

キーワード

検索結果

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

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

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

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

@param mutex Mutex オブ...

NEWS for Ruby 2.0.0 (108.0)

NEWS for Ruby 2.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...bject.const_get("Foo::Bar::Baz")
//}

* Mutex
* 追加(実験的): Mutex#owned? mutex が現在のスレッドに所持されているかどうかを返します
* 非互換:
* Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize, Mutex#sleep
はトラップハンド...
...ラの中では使えなくなりました。そのようなときは ThreadError が発生します
* Mutex#sleep may spurious wakeup. Check after wakeup.

* NilClass
* 追加: NilClass#to_h 空のハッシュを返します

* ObjectSpace::WeakMap
* 弱い参照を保持するた...
...ed.
* 拡張: IO#raw, IO#raw!, IO#getch キーワード引数 :min, :time を受け付けます。

* io/wait
* 追加: IO#wait_writable
* 追加: IO#wait_readable は IO#wait の別名です。

* json
* 1.7.7 に更新

* net/http
* 新機能
* Proxies are now autom...

Thread::ConditionVariable (96.0)

スレッドの同期機構の一つである状態変数を実現するクラスです。

...れるまで wait メソッドで
スレッドを止めます。他のスレッド b において条件が満たされたなら signal
メソッドでスレッド a に対して条件が成立したことを通知します。これが典型的な
使用例です。

mutex
= Mutex.new
cv = Co...
...nditionVariable.new

a = Thread.start {
mutex
.synchronize {
...
while (条件が満たされない)
cv.wait(mutex)
end
...
}
}

b = Thread.start {
mutex
.synchronize {
# 上の条件を満たすための...
... wait しています。

require 'thread'

class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex = Mutex.new
@q = []
end

def count
@q.size
end

def enq(v)
@mutex.sync...

Thread::ConditionVariable#broadcast -> self (68.0)

状態変数を待っているスレッドをすべて再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...Variable#wait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//emlist[例][ruby]{
mutex
= Mutex.new
cv = ConditionVariable.new
flg = true

3.times {
Thread.start {
mutex
.synchronize {
puts "a1"
while (flg)
cv.wait(mutex)...
...end
puts "a2"
}
}
}

Thread.start {
mutex
.synchronize {
flg = false
cv.broadcast
}
}

sleep 1

# => a1
# => a1
# => a1
# => a2
# => a2
# => a2
//}...

Thread::ConditionVariable#signal -> self (68.0)

状態変数を待っているスレッドを1つ再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...Variable#wait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//emlist[例][ruby]{
mutex
= Mutex.new
cv = ConditionVariable.new
flg = true

3.times {
Thread.start {
mutex
.synchronize {
puts "a1"
while (flg)
cv.wait(mutex)...
...end
puts "a2"
}
}
}

Thread.start {
mutex
.synchronize {
flg = false
cv.signal
}
}

sleep 1

# => a1
# => a1
# => a1
# => a2
//}...

絞り込み条件を変える

NEWS for Ruby 3.0.0 (42.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...argument will use `"(eval)"` for `__FILE__` and `1` for `__LINE__` in the evaluated code. 4352 17419
* ConditionVariable
* ConditionVariable#wait may now invoke the `block`/`unblock` scheduler hooks in a non-blocking context. 16786
* Dir
* Dir.glob and Dir.[] now sort the results by def...
...values. 15822
* IO
* IO#nonblock? now defaults to `true`. 16786
* IO#wait_readable, IO#wait_writable, IO#read, IO#write and other related methods (e.g. IO#puts, IO#gets) may invoke the scheduler hook `#io_wait(io, events, timeout)` in a non-blocking execution context. 16786
* Kernel...
...y]{
class C; end
module M1; end
module 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...

Monitor (40.0)

スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。

...スレッドの同期機構としてのモニター機能を提供するクラスです。
また同じスレッドから何度も lock できる Mutex としての機能も提供します。

MonitorMixin を include し、いくつかの別名を定義したクラスです。

=== 例

//emlist[...
...quire 'monitor'

buf = []
mon = Monitor.new
empty_cond = mon.new_cond

# consumer
Thread.start do
loop do
mon.synchronize do
empty_cond.wait_while { buf.empty? }
print buf.shift
end
end
end

# producer
while line = ARGF.gets
mon.synchronize do
buf.push(line)
empty_c...
...equire 'monitor'
mon = Monitor.new
mon.synchronize {
mon.synchronize {
}
}
//}

Thread::Mutex ではデッドロックになります。

//emlist[Mutex でデッドロックになる例][ruby]{
mx = Mutex.new
mx.synchronize {
mx.synchronize {
}
}
# => deadlock; recursive locking (ThreadErro...