Bug #1820
closedAlways spawns a thread that loops on the futex syscall
Description
=begin
Starting with Ruby 1.9, every Ruby process starts two threads.
One of these is looping on the futex syscall all the time.
I have attached an strace log of irb.
Ruby 1.9.0 had the same problem, but it was a different syscall.
I tested this on Debian GNU/Linux, but the problem also existed on Gentoo Linux.
It still exists with the recent Ruby 1.9.2 preview release:
=end
Files
Updated by rogerdpack (Roger Pack) almost 15 years ago
- Status changed from Open to Rejected
=begin
I think this is expected since it spawn one thread to just handle incoming signals. If it's not then please reopen.
-r
=end
Updated by mxey (Maximilian Gass) over 14 years ago
=begin
I see no problem with spawning an extra thread to handle signals. But if that is true, the extra thread should actually wait for a signal using the pause() syscall instead of looping continously.
=end
Updated by rogerdpack (Roger Pack) over 14 years ago
=begin
Is it using 100% of one core?
With my irb (ubuntu), 1.9.1p376 here's my strace without entering the key "3" and hitting enter:
It seems to not be looping (if at all).
With windows (ruby -e 'sleep')
I get this trace (repeated about 100x/s)
[T4252] WaitForSingleObject(798, a, 80502f6a, b34b2ca0, ...) = 102
[T4252] WaitForSingleObject(798, a, 80502f6a, b34b2ca0, ...) = 102
[T4252] WaitForSingleObject(798, a, 80502f6a, b34b2ca0, ...) = 102
Which I think is just the signal thread waking up and then going back to sleep, and appears to use 0% cpu.
What version of readline do you have? Is yours more frequent than this?
Thanks.
-r
=end
Updated by mxey (Maximilian Gass) over 14 years ago
=begin
It is not using 100% of one core, not at all. But it causes frequent wakeups that prevent the CPU from going to sleep. I first stumbled upon this by using powertop.
Did you run strace with -f to follow the extra thread it creates? Otherwise you will just attach to the first one and not notice the other one.
I doubt the problem is related to readline at all. The looping also happens when you run just ruby instead of irb.
=end
Updated by rogerdpack (Roger Pack) over 14 years ago
- Status changed from Rejected to Open
=begin
ahh it appears to also wake up once every 10ms in linux.
Anybody know if this is avoidable by using pause(), as Maximilian suggests?
-rp
=end
Updated by mame (Yusuke Endoh) over 14 years ago
- Status changed from Open to Rejected
=begin
Hi,
That is the timer thread which triggers context switch of Ruby-level
threads. Thus, this is not a bug. I close the ticket.
There may be some optimization to remove the thread, but I have no
concrete idea. If you have, please register it into Feature tracker.
--
Yusuke Endoh mame@tsg.ne.jp
=end