From: Bill Kelly Date: 2004-08-26T18:27:08+09:00 Subject: Re: [BUG?] apparent hang (win32 and Linux), have stack trace Hi again, I wondered if I could check an assumption or two here... I have a slightly tweaked version of the prior script, which for whatever reason seems to hang even more quickly. (Seconds to minutes....) http://bwk.homeip.net/ftp/buffered-io-test4b.rb I've recompiled ruby without optimization so I can see what's going on in the debugger more easily. One assumption I'd like to check, is whether a (delay == DELAY_INFTY) select should *ever* occur in rb_thread_schedule while my script is running. I am thinking this should not occur, because my main thread *only* ever sleeps in the following situation: begin alarm_th = Thread.start { sleep timeout_secs $global_signal.broadcast # %%WAS: .signal } $global_mutex.synchronize { print "{" $global_signal.wait($global_mutex) print "}" } ensure alarm_th.kill if alarm_th and alarm_th.alive? end ...that is, my main thread only goes to sleep when another thread has specifically been created with a non-INFTY delay (sleep timeout_secs) in order to wake my main thread up. So, I'd think that there should be no way to get a (delay == DELAY_INFTY) in rb_thread_schedule. ...UNLESS... . . . The other assumption I'd like to check: My main thread also reads and writes to a socket: if select(nil, [$cl_sock], nil, 0) print "W" sent = $cl_sock.send(" #$frame ", 0) end if select([$cl_sock], nil, nil, 0) print "R" dat = $cl_sock.recv(65536) end ... my assumption here is that send/recv WILL NOT block, because select just told me the socket is readable or writable. (No other thread is touching this socket.) According to what I'm seeing in the debugger, what is apparently happening is that I eventually get a (delay == DELAY_INFTY) select, and it waits forever. Also - it would appear this hanging condition only occurs when the main thread is in the: print "{" -> $global_signal.wait($global_mutex) print "}" ...and never in the send/recv part of the code. So it seems a (delay == DELAY_INFTY) is happening there, when I think it shouldn't.... Am I wrong? Thanks for your help, Regards, Bill