るりまサーチ

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

別のキーワード

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

キーワード

検索結果

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

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

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

@param mutex Thread::Mutex...
...ます。この場合はシグナルを受け取
らなかった場合でも指定した秒数が経過するとスリープを終了
します。省略するとスリープし続けます。

@see Thread::ConditionVariable#signal, Thread::ConditionVariable#broadcast...

Thread::ConditionVariable (68.0)

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

...クラスです。

以下も ConditionVariable を理解するのに参考になります。

https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとします。スレッド A は現在空いてい...
...例です。

mutex
= Mutex.new
cv = ConditionVariable.new

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

b = Thread.start {
mutex
.synchronize...
...e '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) i...

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

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

...開された
スレッドは Thread::ConditionVariable#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 (48.0)

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

...開された
スレッドは Thread::ConditionVariable#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
//}...