るりまサーチ

最速Rubyリファレンスマニュアル検索!
38件ヒット [1-38件を表示] (0.033秒)
トップページ > ライブラリ:ビルトイン[x] > クエリ:@[x] > クエリ:synchronize[x]

別のキーワード

  1. mutex_m synchronize
  2. mutex_m mu_synchronize
  3. monitor synchronize
  4. monitor mon_synchronize
  5. pstore synchronize

キーワード

検索結果

Mutex#synchronize { ... } -> object (18115.0)

mutex をロックし、ブロックを実行します。実行後に必ず mutex のロックを解放します。

...ロックを実行します。実行後に必ず mutex のロックを解放します。

ブロックが最後に評価した値を返します。

@
raise ThreadError self 既にカレントスレッドにロックされている場合に発
生します。
...
...た、Signal.#trap に指定したハンドラ内で実行
した場合に発生します。

//emlist[例][ruby]{
m = Mutex.new
result = m.synchronize do
m.locked? # => true
# critical part
"result"
end
m.locked? # => false
result # => "result"
//}...

Thread::Mutex#synchronize { ... } -> object (18115.0)

mutex をロックし、ブロックを実行します。実行後に必ず mutex のロックを解放します。

...ロックを実行します。実行後に必ず mutex のロックを解放します。

ブロックが最後に評価した値を返します。

@
raise ThreadError self 既にカレントスレッドにロックされている場合に発
生します。
...
...た、Signal.#trap に指定したハンドラ内で実行
した場合に発生します。

//emlist[例][ruby]{
m = Mutex.new
result = m.synchronize do
m.locked? # => true
# critical part
"result"
end
m.locked? # => false
result # => "result"
//}...

Thread::ConditionVariable (116.0)

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

...onVariable.new

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

b = Thread.start {
mutex.synchronize {
# 上の条件を満たすための操...
...@q が空になった場合、
あるいは満タンになった場合に Condition Variable を使って 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.synchronize{
@
full.wait(@mutex) if count == @max
@
q.push v
@
empty.signal if count == 1
}
end

def deq
@
mutex.synchronize{
@
empty.wait(@mutex) if co...

Thread::ConditionVariable#broadcast -> self (20.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)...

Thread::ConditionVariable#signal -> self (20.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)...

絞り込み条件を変える