mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
revert r65822
Because mon_initialized may be used to re-initialize copied objects intentionally. mon_initialize_spec.rb fails: 1) MonitorMixin#mon_initialize can be called in initialize_copy to get a new Mutex and used with synchronize ERROR ThreadError: already initialized /home/shugo/src/ruby/lib/monitor.rb:255:in `mon_initialize' /home/shugo/src/ruby/spec/ruby/library/monitor/mon_initialize_spec.rb:19:in `initialize_copy' /home/shugo/src/ruby/spec/ruby/library/monitor/mon_initialize_spec.rb:28:in `initialize_dup' /home/shugo/src/ruby/spec/ruby/library/monitor/mon_initialize_spec.rb:28:in `dup' /home/shugo/src/ruby/spec/ruby/library/monitor/mon_initialize_spec.rb:28:in `block (2 levels) in <top (required)>' /home/shugo/src/ruby/spec/ruby/library/monitor/mon_initialize_spec.rb:4:in `<top (required)>' git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65827 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
312fc605c1
commit
0dfc5918ec
2 changed files with 1 additions and 41 deletions
|
@ -251,12 +251,9 @@ module MonitorMixin
|
||||||
# Initializes the MonitorMixin after being included in a class or when an
|
# Initializes the MonitorMixin after being included in a class or when an
|
||||||
# object has been extended with the MonitorMixin
|
# object has been extended with the MonitorMixin
|
||||||
def mon_initialize
|
def mon_initialize
|
||||||
if defined?(@mon_mutex)
|
|
||||||
raise ThreadError, "already initialized"
|
|
||||||
end
|
|
||||||
@mon_mutex = Thread::Mutex.new
|
|
||||||
@mon_owner = nil
|
@mon_owner = nil
|
||||||
@mon_count = 0
|
@mon_count = 0
|
||||||
|
@mon_mutex = Thread::Mutex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def mon_check_owner
|
def mon_check_owner
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
# frozen_string_literal: false
|
|
||||||
require 'test/unit'
|
|
||||||
require 'monitor'
|
|
||||||
|
|
||||||
class TestMonitorMixin < Test::Unit::TestCase
|
|
||||||
def test_cond
|
|
||||||
a = "foo"
|
|
||||||
a.extend(MonitorMixin)
|
|
||||||
cond = a.new_cond
|
|
||||||
queue1 = Queue.new
|
|
||||||
th = Thread.start do
|
|
||||||
queue1.deq
|
|
||||||
a.synchronize do
|
|
||||||
a.replace("bar")
|
|
||||||
cond.signal
|
|
||||||
end
|
|
||||||
end
|
|
||||||
th2 = Thread.start do
|
|
||||||
a.synchronize do
|
|
||||||
queue1.enq(nil)
|
|
||||||
assert_equal("foo", a)
|
|
||||||
result1 = cond.wait
|
|
||||||
assert_equal(true, result1)
|
|
||||||
assert_equal("bar", a)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
assert_join_threads([th, th2])
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_initialize_twice
|
|
||||||
a = Object.new
|
|
||||||
a.extend(MonitorMixin)
|
|
||||||
assert_raise(ThreadError) do
|
|
||||||
a.send(:mon_initialize)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Add a link
Reference in a new issue