Skip to content

Commit

Permalink
Merge pull request #665 from meineerde/fix/rbx_array_monitor
Browse files Browse the repository at this point in the history
Initialize the monitor for new subarrays on Rubinius
  • Loading branch information
pitr-ch committed Jul 23, 2017
2 parents 264e2c1 + 91170af commit df482db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/concurrent/thread_safe/util/array_hash_rbx.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/concurrent/array_spec.rb
Expand Up @@ -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.