Skip to content

Commit 0ace358

Browse files
committed
Make sure locks are not shared on shared when objects are dup/cloned
1 parent b57b483 commit 0ace358

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def initialize(*defaults)
3232
@__Condition__ = ::ConditionVariable.new
3333
end
3434

35+
def initialize_copy(other)
36+
super
37+
@__Lock__ = ::Mutex.new
38+
@__Condition__ = ::ConditionVariable.new
39+
end
40+
3541
protected
3642

3743
def synchronize
@@ -61,6 +67,12 @@ def initialize(*defaults)
6167
@__Condition__ = @__Lock__.new_cond
6268
end
6369

70+
def initialize_copy(other)
71+
super
72+
@__Lock__ = ::Mutex.new
73+
@__Condition__ = @__Lock__.new_cond
74+
end
75+
6476
protected
6577

6678
def synchronize # TODO may be a problem with lock.synchronize { lock.wait }

lib/concurrent-ruby/concurrent/synchronization/rbx_lockable_object.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def initialize(*defaults)
1212
@__owner__ = nil
1313
end
1414

15+
def initialize_copy(other)
16+
super
17+
@__Waiters__ = []
18+
@__owner__ = nil
19+
end
20+
1521
protected
1622

1723
def synchronize(&block)

0 commit comments

Comments
 (0)