Project

General

Profile

Actions

Feature #5654

open

Introduce global lock to avoid concurrent require

Added by nahi (Hiroshi Nakamura) about 13 years ago. Updated almost 7 years ago.

Status:
Assigned
Target version:
-
[ruby-core:<unknown>]

Description

=begin
Current implementation of "require" has locks for each file (expanded name from required feature) and serializes file loading from Threads. The first Thread acquires the lock for the file and starts loading. The second Thread waits for acquiring the lock, and when the first Thread release the lock, it acquires the lock, then returns immediately.
This can cause deadlock by cross-require from Threads.

And code that does not properly use "require" could meet several problems;

  • constants can be defined before they're ready for use
  • classes can be modified while they're being used
  • global state can be initialized at the same time it's in use

Proposal: introduce global (per VM) lock to avoid concurrent file loading by "require" so that only one Thread can call "require" at the same time.

I don't have pros/cons list at this moment. Let's discuss it, too.

Derived from a discussion at #5621 (thread-safe autoload)
=end


Files

5654.pdf (34.1 KB) 5654.pdf nahi (Hiroshi Nakamura), 07/01/2012 12:24 AM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #11277: "code converter not found" error with multi-thread (high occurrence rate since r50887)ClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0