summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-05 09:07:54 +0000
committerkazu <kazu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-05 09:07:54 +0000
commit1eba8ecb6643d080ad8e08974644964c368eb4a9 (patch)
tree56e6ddcb841523891b3eef14d1e050fcf8f0c756
parent39130926240f87f9bc0123df0db180b71ada4cc4 (diff)
lib/monitor.rb: prevent to initialize MonitorMixin twice
and allow to initialize again when obj.dup. Suggested by Benoit Daloze. [ruby-core:88504] [Feature #15000] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/monitor.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 2a59fa7cc0..999795c3d0 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -255,9 +255,13 @@ 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) && @mon_mutex_owner_object_id == object_id
+ raise ThreadError, "already initialized"
+ end
+ @mon_mutex = Thread::Mutex.new
+ @mon_mutex_owner_object_id = object_id
@mon_owner = nil
@mon_count = 0
- @mon_mutex = Thread::Mutex.new
end
def mon_check_owner