Project

General

Profile

Actions

Bug #13735

closed

Initialization-error of sortedset

Added by junjihashimoto (Junji Hashimoto) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]ca
[ruby-core:81985]

Description

When we use multithreading environment, sortedset-initialization always fails.

Reproducible programs and the logs are below.

$ cat sortedset-test.rb
require "set"

def func1
  set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
  ary = []

  set.each do |obj|
    ary << obj
    p ary
  end
end

def func2
  set = SortedSet.new([2, 1, 5, 6, 4, 5, 3, 3, 3])
  ary = []

  set.each do |obj|
    ary << obj
    p ary
  end
end

puts "Started At #{Time.now}"
t1 = Thread.new{func1()}
t2 = Thread.new{func2()}
t1.join
t2.join
puts "End at #{Time.now}"

$ ruby  sortedset-test.rb
Started At 2017-07-10 10:08:14 +0900
[1]
[1, 2]
[1, 2, 3]
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
/home/hogeuser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/set.rb:711:in `remove_method': method `old_init' not defined in SortedSet (NameError)
        from /home/hogeuser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/set.rb:711:in `block in setup'
        from /home/hogeuser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/set.rb:709:in `module_eval'
        from /home/hogeuser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/set.rb:709:in `setup'
        from /home/hogeuser/.rbenv/versions/2.4.1/lib/ruby/2.4.0/set.rb:719:in `initialize'
        from sortedset-test.rb:15:in `new'
        from sortedset-test.rb:15:in `func2'
        from sortedset-test.rb:26:in `block in <main>'

Following tickets may have a same problem.

https://github.com/jubos/fake-s3/pull/55
https://github.com/synthetichealth/synthea/issues/156

Following link has initialization error of sortedset, too.
But it does not use multithreading.

https://stackoverflow.com/questions/41815930/ruby-marshal-load-doesnt-keep-order-of-sorted-set

Actions #1

Updated by junjihashimoto (Junji Hashimoto) over 6 years ago

  • Description updated (diff)
Actions #2

Updated by junjihashimoto (Junji Hashimoto) over 6 years ago

  • Subject changed from Initializing error of sortedset to Initialization-error of sortedset

Updated by knu (Akinori MUSHA) over 6 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)
Actions #4

Updated by knu (Akinori MUSHA) over 6 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r60304.


Use a mutex to make SortedSet.setup thread-safe

This should fix [Bug #13735].

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0