From 886e0a006d9e8e9c586beae28ed4dc5097064e90 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 20 Dec 2010 03:41:48 +0000 Subject: thread_timeout: avoid a threading bug under 1.9 Because of the lack of GVL-releasing syscalls in this branch of the thread loop, we need Thread.pass to ensure other threads get scheduled appropriately under 1.9. This is likely a threading bug in 1.9 that warrants further investigation when we're in a better mood. --- lib/rainbows/thread_timeout.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rainbows/thread_timeout.rb b/lib/rainbows/thread_timeout.rb index f34c0d4..b9f6025 100644 --- a/lib/rainbows/thread_timeout.rb +++ b/lib/rainbows/thread_timeout.rb @@ -73,7 +73,13 @@ class Rainbows::ThreadTimeout begin if next_wake = @lock.synchronize { @active.values }.min next_wake -= Time.now - sleep(next_wake) if next_wake > 0 + + # because of the lack of GVL-releasing syscalls in this branch + # of the thread loop, we need Thread.pass to ensure other threads + # get scheduled appropriately under 1.9. This is likely a threading + # bug in 1.9 that warrants further investigation when we're in a + # better mood. + next_wake > 0 ? sleep(next_wake) : Thread.pass else sleep(@timeout) end -- cgit v1.2.3-24-ge0c7