So, we’re trying to debug a problem with an app of ours and we think we’ve narrowed it down to a threading issue.
I understand based on Ruby’s documentation on Thread that providing an integer argument to the join method specifies how long it will wait for the thread to join up before just returning nil.
However, I’m not sure what happens when you pass in ‘0.’
One of my colleagues, after digging around in the C code for the Ruby interpreter, seems to think that it’s not “don’t wait at all just join it immediately and return nil if it doesn’t come back” and is more along the lines of “don’t bother joining and just return a snapshot of the thread at the given moment.”
Can anyone point me to some documentation on (or just flat out tell me) what passing a ‘0’ argument to join() does?
After testing the code by Diego Basch:
fandgare very similar.The reason for this is that f is just the limit — put in as small of a number as possible.
And they mean the same thing. Check virtually immediately to see if the thread is done. When it isn’t, return nil.
Thus in the code above, the until repeatedly evaluates in the first 2 cases but only evaluates a couple of times in the third case (in particular, every 0.15 seconds). Using 0 as a parameter functions exactly like every other number — check to see if the thread is done in the next 0 seconds (now) and if it isn’t return nil.
I’m afraid your colleague is not correct.