[ruby-core:78352] [Ruby trunk Bug#12688] Thread unsafety in autoload
From:
shyouhei@...
Date:
2016-11-25 13:35:27 UTC
List:
ruby-core #78352
Issue #12688 has been updated by Shyouhei Urabe.
We looked at this issue in todays developer meeting and had 2 feelings in common.
1. The autoload should not render NameError. It definitely is a bug that must be fixed. Ko1 is assigned.
2. Besides, we want to discourage people from doing something like `1 until go`. JRuby+Truffle might optimize this out (as far as I understand). Also generally speaking, sharing local variables across threads is something difficult to do properly.
----------------------------------------
Bug #12688: Thread unsafety in autoload
https://bugs.ruby-lang.org/issues/12688#change-61724
* Author: Charles Nutter
* Status: Assigned
* Priority: Normal
* Assignee: Koichi Sasada
* ruby -v: 2.3.0
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
I need clarification here. I expected, based on Ruby's assertion that autoloads are thread-safe, that the following code would never error. Instead, it gets a couple iterations in and raises NameError:
```ruby
loop do
class Foo
autoload :Bar, 'bar.rb'
end
go = false
threads = (1..50).map {Thread.new { 1 until go; print '.'; Foo.const_get(:Bar) }}
go = true
threads.each(&:join)
puts
self.class.send :remove_const, :Foo
end
```
And the output with Ruby 2.3.0:
```
$ ruby23 -I. autoload_breaker.rb
..................................................
..................................................autoload_breaker.rb:7:in `const_get': uninitialized constant Foo::Bar (NameError)
Did you mean? Foo::Bar
from autoload_breaker.rb:7:in `block (3 levels) in <main>'
```
Is there something wrong with my script? Is my expectation incorrect?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>