Sandor Szücs
5/9/2009 12:32:00 PM
On 05.05.2009, at 14:35, Guillaume Gdo wrote:
> mutex=3DMutex.new
> mutex.synchronize do
> mutex.synchronize do
> puts "A"
> puts "B"
> end
> end
Mutex is not reentrant.
irb> m=3DMutex.new
irb> m.synchronize do
irb> puts "foo"
irb> m.synchronize do
irb> puts "bar"
irb> end
irb> end
foo
ThreadError: thread 0x341ac tried to join itself
from (irb):4:in `synchronize'
from (irb):4
from (irb):2:in `synchronize'
from (irb):2
> Nevertheless my thread have a lock on the mutex. How to reuse it ?
Use Monitor instead of Mutex.
irb> m=3DMonitor.new
irb> m.synchronize do
irb> puts "foo"
irb> m.synchronize do
irb> puts "reentrant"
irb> end
irb> end
foo
reentrant
hth. Sandor Sz=FCcs
--