ruby-changes:53611
From: shugo <ko1@a...>
Date: Tue, 20 Nov 2018 12:56:57 +0900 (JST)
Subject: [ruby-changes:53611] shugo:r65827 (trunk): revert r65822
shugo 2018-11-20 12:56:51 +0900 (Tue, 20 Nov 2018) New Revision: 65827 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65827 Log: 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)>' Removed files: trunk/test/monitor/test_monitor_mixin.rb Modified files: trunk/lib/monitor.rb Index: test/monitor/test_monitor_mixin.rb =================================================================== --- test/monitor/test_monitor_mixin.rb (revision 65826) +++ test/monitor/test_monitor_mixin.rb (nonexistent) @@ -1,37 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/test/monitor/test_monitor_mixin.rb#L0 -# 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 Property changes on: test/monitor/test_monitor_mixin.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Index: lib/monitor.rb =================================================================== --- lib/monitor.rb (revision 65826) +++ lib/monitor.rb (revision 65827) @@ -251,12 +251,9 @@ module MonitorMixin https://github.com/ruby/ruby/blob/trunk/lib/monitor.rb#L251 # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/