From: Charles O Nutter Date: 2004-10-31T12:44:27+09:00 Subject: Possible flaw in rubicon test for TestThreadGroup Hello! I'm trying to implement Thread and ThreadGroup semantics for JRuby, and have run into an issue with one of the rubicon tests; specifically, the "test_list" test in TestThreadGroup. The test is as follows: def test_list tg = ThreadGroup.new 10.times do Thread.critical = true t = Thread.new { Thread.stop } tg.add(t) end assert_equal(10, tg.list.length) tg.list.each {|t| t.wakeup; t.join } end The problem I'm running into is that there's no guarantee that Thread.stop will be called in the ten threads created before t.wakeup is called below. In JRuby, since Ruby threads are mapped directly to JVM threads (and by extension, to native threads), this test usually just freezes up. That's because t.wakeup is called before the thread has been scheduled to run; t.join is then called, the thread in question Thread.stops, and that's that. If I replace the tg.list.each... line above with the following: tg.list.each do |t| Thread.pass while (t.status != "sleep") t.wakeup t.join end ...The test succeeds every time. The Thread.pass line is also very common throughout tests in TestThread.rb. I'm trying to determine whether this is a flaw in the way I've implemented stop and wakeup, or if there's an issue with this test. Comments?