I recently learned about timeout (forum does not allow me to link to github).
I read into its source code - it uses Ractor features, Fiber features and Thread features – the code is too clever for me to understand.
I have had the assumption that MRI-4 (ruby-4.0.1) does not preempt threads. Here is an example code that underpins my mental modell
def cpu_load()
i=0
while
Math.sqrt(i)
puts "t=#{Thread.current} i=#{i}" if i%400_000==0
i += 1
end
end
thread_list=[]
thread_list << Thread.new() do
cpu_load
end
thread_list << Thread.new() do
cpu_load
end
thread_list.each do
_1.join
end
If you run the example, MRI-4 never switches the currently executing thread. So how does Timeout.timeout achieve to get scheduled?