Project

General

Profile

Bug #13735

Initialization-error of sortedset

Added by junjihashimoto (Junji Hashimoto) about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 8daa6985
Added by knu (Akinori MUSHA) almost 2 years ago

Use a mutex to make SortedSet.setup thread-safe

This should fix [Bug #13735].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 60304
Added by knu (Akinori MUSHA) almost 2 years ago

Use a mutex to make SortedSet.setup thread-safe

This should fix [Bug #13735].

Revision 60304
Added by knu (Akinori MUSHA) almost 2 years ago

Use a mutex to make SortedSet.setup thread-safe

This should fix [Bug #13735].

Revision 60304
Added by knu (Akinori MUSHA) almost 2 years ago

Use a mutex to make SortedSet.setup thread-safe

This should fix [Bug #13735].

History

#1

Updated by junjihashimoto (Junji Hashimoto) about 2 years ago

  • Description updated (diff)
#2

Updated by junjihashimoto (Junji Hashimoto) about 2 years ago

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

Updated by knu (Akinori MUSHA) about 2 years ago

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

Updated by knu (Akinori MUSHA) almost 2 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].

Also available in: Atom PDF