mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
parent
e8f65e017b
commit
9b1c8ecad3
1 changed files with 21 additions and 0 deletions
|
@ -200,6 +200,27 @@ class TestRactor < Test::Unit::TestCase
|
|||
RUBY
|
||||
end
|
||||
|
||||
# [Bug #20346]
|
||||
def test_many_ractors_in_threads
|
||||
assert_ractor(<<~'RUBY')
|
||||
Warning[:experimental] = false
|
||||
|
||||
N = 100
|
||||
ractors = N.times.map do
|
||||
Ractor.new do
|
||||
Ractor.recv # Ractor doesn't start until explicitly told to
|
||||
# Do some calculations
|
||||
fib = ->(x) { x < 2 ? 1 : fib.call(x - 1) + fib.call(x - 2) }
|
||||
fib.call(20)
|
||||
end
|
||||
end
|
||||
|
||||
threads = ractors.map { |r| Thread.new { r.value } }
|
||||
ractors.each { |r| r.send(nil) }
|
||||
threads.each(&:join)
|
||||
RUBY
|
||||
end
|
||||
|
||||
def assert_make_shareable(obj)
|
||||
refute Ractor.shareable?(obj), "object was already shareable"
|
||||
Ractor.make_shareable(obj)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue