Possible flaw in rubicon test for TestThreadGroup

C

Charles O Nutter

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,422
Latest member
LatashiaZc

Latest Threads

Top