Project

General

Profile

Actions

Bug #17742

closed

Random.rand gets wrong after using Ractor and requiring benchmark

Added by andras@frontfoo.com (Andras Horvath) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]
[ruby-core:102984]

Description

Dear All,

I use Ruby v3.0.0 on Ubuntu 18.04 x64 compiled from source the recommended way and when I run the following code:

require "benchmark"; r = []; 3.times.map{ r << Ractor.new{ p receive } }; r.map{|x| x.send(rand) }; rand

Then the "rand" method gets messed up. Running simply "rand" give weird values like 0.00000 or 1.0 or 0.3.

The same issue happens when running from pry or the installed irb shell or even when running from command line with the -e option.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #17612: ractor crash with some simple codesClosedko1 (Koichi Sasada)Actions

Updated by xtkoba (Tee KOBAYASHI) over 3 years ago

I cannot reproduce this with a recent development version (3.1.0dev) on Git. It is possible that this issue has already been fixed, although I cannot point out exactly when it was fixed.

FWIW, I can reproduce this with Ruby 3.0.0p0, and it is not necessary to require benchmark.

$ cat bug17742.rb
r = []
3.times.map{ r << Ractor.new{ p receive } }
r.map{|x| x.send(rand) }
p rand
sleep 1

$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm-linux-android]

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
0.9;
0.9O
0.1
0.1

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
0.308592334553756
0.05065486369735517
0.6489208709468116
0.042977039455267096

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
0.3780271760002001
0.2946530653738084
0.7840270366549699
0.04166502381699466

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
0.9371173786797564
0.02501308906114741
0.7470842632567019
0.847737184948548

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
0.3578481078852569
0.4340746690184164
0.2731715341203722
0.6503945796067339

$ ruby --disable-gems bug17742.rb
<internal:ractor>:267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
1.0
0.2
0.9
1.0

Updated by byroot (Jean Boussier) over 3 years ago

It is possible that this issue has already been fixed

I think so too. I compiled the ruby_3_0 branch (what will later be 3.0.1) and can't reproduce there. However I can repro with 3.0.0-p0.

Updated by wanabe (_ wanabe) over 3 years ago

I think that it is fixed by 3acc81d9.

$ cat test.rb 
10.times do
  r = 100.times.map { Ractor.new{ Ractor.yield(receive.inspect) } }
  r.each{|x| x.send(rand) }
  s = r.map{|x| x.take }.min_by(&:size)
  puts s
  if s.size < 10
    puts "NG"
    exit(1)
  end
end
puts "OK"


$ git checkout 3acc81d9~; make -j6 miniruby
(snip)

$ ./miniruby -v0 -W0 test.rb 
ruby 3.1.0dev (2021-02-10T10:42:00Z save ad2c7f8a1e) [x86_64-linux]
1.0
NG

$ git checkout 3acc81d9; make -j6 miniruby
(snip)

$ ./miniruby -v0 -W0 test.rb
ruby 3.1.0dev (2021-02-10T10:44:47Z save 3acc81d9e4) [x86_64-linux]
0.546287565846683
0.872517066423101
0.6116641504914
0.162459674285925
0.95763200302244
0.970595118290251
0.297374935301547
0.59711433534198
0.71000638880677
0.722584124112161
OK

Actions #4

Updated by wanabe (_ wanabe) over 3 years ago

  • Related to Bug #17612: ractor crash with some simple codes added
Actions #5

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0