Skip to content

Commit b57399f

Browse files
author
Yorick Peterse
committedApr 24, 2015
Synchronize calls to Autoload#resolve
When multiple threads attempt to resolve an autoload definition there's nothing guarding the checks/sets for the "@loaded" and "@thread" instance variables. By using Rubinius.synchronize we can ensure that only 1 thread at a time can autoload a constant without having to worry about recursive locking.
1 parent 29316ad commit b57399f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

Diff for: ‎kernel/common/autoload.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ def call(under, honor_require=false)
4949
end
5050

5151
def resolve
52-
unless @loaded && @thread == Thread.current
53-
@loaded = true
54-
@thread = Thread.current
55-
Rubinius::CodeLoader.require @path
52+
Rubinius.synchronize(self) do
53+
unless @loaded && @thread == Thread.current
54+
@loaded = true
55+
@thread = Thread.current
56+
Rubinius::CodeLoader.require @path
57+
end
5658
end
5759
end
5860

0 commit comments

Comments
 (0)
Please sign in to comment.