From: Wilson Bilkovich Date: 2005-11-09T03:52:55+09:00 Subject: Checking for race conditions with Ruby threads I've got an untrustworthy legacy app that seems to have a nasty race condition when a certain number of users click on a link at just the right time. I'm trying to write a Ruby unit test to trigger this, but I'm a bit stumped. Here's my code: require 'test/unit' require 'open-uri' class TestStream < Test::Unit::TestCase def test_work_unit_uniqueness ids = [] threads = [] 100.times do |i| threads[i] = Thread.new do Thread.current[:appid] = URI("http://the_test_url/something").read end end ids = threads.collect {|t| t.join ; t[:appid]} assert_equal(ids, ids.uniq) end end The test URL spits back a single number, in plain text. The idea is to hit it 100 times, and make sure that each 'worker' thread got a unique number. However, it seems to me that with green threads, the OS running on the Ruby machine will actually serialize these requests. Do I need to switch to Linux and use 'fork', or is there another way to handle this? Thanks, --Wilson.