Skip to content

Commit

Permalink
Synchronize calls to Autoload#resolve
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Yorick Peterse committed Apr 24, 2015
1 parent 29316ad commit b57399f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions kernel/common/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ def call(under, honor_require=false)
end

def resolve
unless @loaded && @thread == Thread.current
@loaded = true
@thread = Thread.current
Rubinius::CodeLoader.require @path
Rubinius.synchronize(self) do
unless @loaded && @thread == Thread.current
@loaded = true
@thread = Thread.current
Rubinius::CodeLoader.require @path
end
end
end

Expand Down

0 comments on commit b57399f

Please sign in to comment.