Project

General

Profile

Actions

Bug #18663

closed

Autoload doesn't work with fiber context switch.

Added by ioquatix (Samuel Williams) about 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:108075]

Description

As discussed most recently here: https://github.com/ruby/debug/issues/580

The following program appears to work:

#!/usr/bin/env ruby

require 'tempfile'

Tempfile.create(['foo', '.rb']) do |file|
  file.write(<<~RUBY)
    #
    $stderr.puts 1; q = Queue.new
    $stderr.puts 2; t = Thread.new{q.pop}
    $stderr.puts 3; q << :sig
    $stderr.puts 4; t.join

    sleep 1

    class C
    end
  RUBY
  file.close

  autoload :C, file.path

  Thread.new do
    threads = 3.times.map do |i|
      Thread.new do
        $stderr.puts "LOADING C" 
        $stderr.puts C
      end
    end

    threads.each(&:join)
  end.join
end

This one doesn't:

#!/usr/bin/env ruby

require 'tempfile'
require_relative 'lib/async'

Tempfile.create(['foo', '.rb']) do |file|
  file.write(<<~RUBY)
    #
    $stderr.puts 1; q = Queue.new
    $stderr.puts 2; t = Thread.new{q.pop}
    $stderr.puts 3; q << :sig
    $stderr.puts 4; t.join

    class C
    end
  RUBY
  file.close

  autoload :C, file.path

  Async do |task|
    3.times do |i|
      task.async do
        $stderr.puts "LOADING C" 
        $stderr.puts C
      end
    end
  end.wait
end

Semantically, they should be very similar. It feels like someone is checking the current thread rather than the current fiber or there is a poor implementation of locking somewhere, however I don't actually know for sure yet, investigation is required.


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Misc #18662: Fiber scheduling and Module#autoloadClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0