Ruby, Threads and Exit Codes
2008-05-06
A question for you Ruby nerds: the $? variable gives access to the exit code for the last process launched by Ruby. Is referencing $? a race condition in a system with many threads launching many subprocesses? If it is truly a global variable, then it’s inherently unsafe, but it could also be implemented with a thread-local variable. Any idea which it is?
output = `#{command}`
if $? != 0 # Race condition?
raise output
end
Update: modern Ruby implements it as a thread-local so it is thread-safe.