Permalink
Browse files

Merge pull request #665 from meineerde/fix/rbx_array_monitor

Initialize the monitor for new subarrays on Rubinius
  • Loading branch information...
pitr-ch committed Jul 23, 2017
2 parents 264e2c1 + 91170af commit df482db36caf1b0c1d69a8ff97a2407469e1e315
Showing with 26 additions and 5 deletions.
  1. +16 −5 lib/concurrent/thread_safe/util/array_hash_rbx.rb
  2. +10 −0 spec/concurrent/array_spec.rb
@@ -18,11 +18,22 @@ def self.allocate
end
klass.superclass.instance_methods(false).each do |method|
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
@_monitor.synchronize { super }
end
RUBY
case method
when :new_range, :new_reserved
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
obj = super
obj.send(:_mon_initialize)
obj
end
RUBY
else
klass.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{method}(*args)
@_monitor.synchronize { super }
end
RUBY
end
end
end
end
@@ -14,5 +14,15 @@ module Concurrent
end
end.map(&:join)
end
describe '#slice' do
# This is mostly relevant on Rubinius and Truffle
it 'correctly initializes the monitor' do
ary.concat([0, 1, 2, 3, 4, 5, 6, 7, 8])
sliced = ary.slice!(0..2)
expect { sliced[0] }.not_to raise_error
end
end
end
end

0 comments on commit df482db

Please sign in to comment.