3

In multi-threaded ruby execution, you cannot get parallel execution of threads unless you use those functions which frees GVL.

In my understanding, following ruby methods frees GVL:

  • Kernel#sleep
  • IO#read and IO#write

Question

  • In pure ruby, is there any other methods which frees GVL?

Version

  • I'm currently using ruby version 2.6, so expect the info of this version.
Yuki Inoue
  • 3,569
  • 5
  • 34
  • 53

2 Answers2

1

I asked same question on stackoverflow (Japanese).

Got this answer https://ja.stackoverflow.com/a/55579/754 , which stating that

  • Bignum's div / modulo
  • Dir.new/Dir.open
  • Dir.chdir
  • Dir.rmdir
  • Dir.empty?
  • Dir.glob
  • File.chown
  • File's methods which check file status, namely stats
  • File.rename
  • File.truncate
  • File.mkfifo
  • IO.copy_stream
  • IO.#open and IO.#close related codes (was too complex to understand)
  • Kernel.#system
  • Kernel.#exec

and in other standard libraries such as fiddle, openssl, readline, socket, zlib actually calls method which frees GVL.

this great answer was written by https://stackoverflow.com/users/4944814/raccy

Yuki Inoue
  • 3,569
  • 5
  • 34
  • 53
0

In pure ruby, is there any other methods which frees GVL?

In pure Ruby, there is no such thing as a GVL. The GVL is a feature of some specific versions of one specific implementation of Ruby. The vast majority of Ruby implementations don't have a GVL or even something remotely similar.

I'm currently using ruby version 2.6, so expect the info of this version.

This is true for all versions of Ruby. No version of Ruby has ever specified the existence of a GVL. And it is highly doubtful that any future version of Ruby will, either.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
  • 1
    I guess by "pure Ruby" the question's author actually ment MRI. – igneus Feb 14 '19 at 21:46
  • 5
    This answer is very misguided. Most interpreted language interpreters make use of a GVL, including Ruby MRI since 1.x through to 3.x. Custom ruby interpreters such as Rubinius and JRuby try to allow true parallel processing. – Tjad Clark Nov 19 '20 at 11:24