Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby threads blocked on calls to C functions #873

Closed
dan-manges opened this issue Jan 31, 2025 · 0 comments · Fixed by #884
Closed

Ruby threads blocked on calls to C functions #873

dan-manges opened this issue Jan 31, 2025 · 0 comments · Fixed by #884

Comments

@dan-manges
Copy link

I think the C extension needs to use rb_thread_call_without_gvl to release the GVL while executing long running I/O. Otherwise, it will block other Ruby threads.

test script

require "duckdb"

t1 = Thread.new do
  loop do
    puts "[t1] #{Time.now}"
    sleep 1
  end
end

t2 = Thread.new do
  loop do
    puts "[t2] Running DuckDB"
    DuckDB::Database.open("/tmp/foo.duckdb") do |db|
      db.connect do |con|
        con.execute "SELECT SUM(random()) FROM range(1000000000);"
      end
    end
    sleep 3
  end
end

t1.join
t2.join

output

[t1] 2025-01-31 10:01:48 -0500
[t2] Running DuckDB
[t1] 2025-01-31 10:01:52 -0500
[t1] 2025-01-31 10:01:53 -0500
[t1] 2025-01-31 10:01:54 -0500
[t2] Running DuckDB
[t1] 2025-01-31 10:01:59 -0500
[t1] 2025-01-31 10:02:00 -0500
[t1] 2025-01-31 10:02:01 -0500
[t2] Running DuckDB
[t1] 2025-01-31 10:02:07 -0500
@dan-manges dan-manges changed the title rb_thread_call_without_gvl Ruby threads blocked on calls to C functions Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant