From 1eba8ecb6643d080ad8e08974644964c368eb4a9 Mon Sep 17 00:00:00 2001 From: kazu Date: Wed, 5 Dec 2018 09:07:54 +0000 Subject: [PATCH] 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 --- lib/monitor.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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