summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-20 03:56:51 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-20 03:56:51 +0000
commit0dfc5918ec19cb67d8a49915ad8ab177f56e4e73 (patch)
treebcf6a376e13dd981a73be23d7e8aa8b3b8dd8557
parent312fc605c1e09c487f66c13fdbcf6bfff44d8b7f (diff)
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
-rw-r--r--lib/monitor.rb5
-rw-r--r--test/monitor/test_monitor_mixin.rb37
2 files changed, 1 insertions, 41 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 86c779f..288ed75 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -251,12 +251,9 @@ module MonitorMixin
# Initializes the MonitorMixin after being included in a class or when an
# object has been extended with the MonitorMixin
def mon_initialize
- if defined?(@mon_mutex)
- raise ThreadError, "already initialized"
- end
- @mon_mutex = Thread::Mutex.new
@mon_owner = nil
@mon_count = 0
+ @mon_mutex = Thread::Mutex.new
end
def mon_check_owner
diff --git a/test/monitor/test_monitor_mixin.rb b/test/monitor/test_monitor_mixin.rb
deleted file mode 100644
index 24ad6b7..0000000
--- a/test/monitor/test_monitor_mixin.rb
+++ /dev/null
@@ -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