G
Guillaume Gdo
Hello, in ruby 1.8.7
I want to do something like this:
require 'thread'
class Bar
def initialize(f)
@f=f
end
def m_a #This method isn't call only by FOO::m_b
@f.m_a
end
end
class Foo
 def initialize
  @mutex=Mutex.new
 end
 def m_a
  @mutex.synchronize do
   puts "A"
  end
 end
 def m_b
  @mutex.synchronize do
   puts "B"
b=Bar.new(self)
b.m_a
  end
 end
end
f=Foo.new
f.m_b
I must have
but I have
B
test.rb:8:in `synchronize': stopping only thread (ThreadError)
    note: use sleep to stop forever
    from test.rb:8:in `m_a'
    from test.rb:16:in `m_b'
    from test.rb:14:in `synchronize'
    from test.rb:14:in `m_b'
    from test.rb:22
because I can't do
mutex=Mutex.new
mutex.synchronize do
mutex.synchronize do
puts "A"
puts "B"
end
end
Nevertheless my thread have a lock on the mutex. How to reuse it ?
Thanks
I want to do something like this:
require 'thread'
class Bar
def initialize(f)
@f=f
end
def m_a #This method isn't call only by FOO::m_b
@f.m_a
end
end
class Foo
 def initialize
  @mutex=Mutex.new
 end
 def m_a
  @mutex.synchronize do
   puts "A"
  end
 end
 def m_b
  @mutex.synchronize do
   puts "B"
b=Bar.new(self)
b.m_a
  end
 end
end
f=Foo.new
f.m_b
I must have
but I have
B
test.rb:8:in `synchronize': stopping only thread (ThreadError)
    note: use sleep to stop forever
    from test.rb:8:in `m_a'
    from test.rb:16:in `m_b'
    from test.rb:14:in `synchronize'
    from test.rb:14:in `m_b'
    from test.rb:22
because I can't do
mutex=Mutex.new
mutex.synchronize do
mutex.synchronize do
puts "A"
puts "B"
end
end
Nevertheless my thread have a lock on the mutex. How to reuse it ?
Thanks