Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRubythe GVL global VM lockSingle-choice MCQ

Two threads run this code on MRI. Counter ends up far below 2_000_000. What is the precise reason the increment can be lost despite the GVL serializing bytecode?

@counter = 0 ts = 2.times.map do Thread.new do 1_000_000.times { @counter += 1 } end end ts.each(&:join) puts @counter