bug involving condition variables

J

Joel VanderWerf

The following code generates a ThreadError ("not owner", raised in
unlock_mutex_inner()). However, the ThreadError never gets reported at
the top level (even though my code is re-raising it and
Thread.abort_on_exception = true). A ThreadError that I raise directly
gets reported normally.

For 1.8.6-p114 (Linux), the output is:

#<ThreadError: not owner>

For 1.8.4, there is no output (so it looks like this difference has
something to do with the thread rewrite in 1.8.6).

If it doesn't look like there's some obvious stupidity, I'll file a bug.

-------------------------------

require 'thread'

Thread.abort_on_exception = true

class MyQueue
def initialize
@q = []
@mutex = Mutex.new
@cond = ConditionVariable.new
end

def push(obj)
@mutex.synchronize do
@q << obj
@cond.signal
end
end

def pop
@mutex.synchronize do
if ([email protected])
return last
end

loop do
@cond.wait(@mutex)
if ([email protected])
return last
end
end
end
end
end

queue = MyQueue.new

def wait(queue)
#raise ThreadError, "foo bar"
# why does this behave differently than
# the "not owner" ThreadError ?
queue.pop
queue.pop

# without the rescue clause the program has no exceptions--why?
rescue ThreadError => ex
p ex
raise ex # Why no exception reported at top level?
end

Thread.new {wait(queue)}

sleep 0.01

Thread.new do
queue.push "foobar"
end

sleep 0.01
 
J

Joel VanderWerf

Same problem on OCI windows:

ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
 
N

Nobuyoshi Nakada

Hi,

At Mon, 14 Jul 2008 15:12:16 +0900,
Joel VanderWerf wrote in [ruby-talk:308103]:
The following code generates a ThreadError ("not owner", raised in
unlock_mutex_inner()). However, the ThreadError never gets reported at
the top level (even though my code is re-raising it and
Thread.abort_on_exception = true). A ThreadError that I raise directly
gets reported normally.

For 1.8.6-p114 (Linux), the output is:

#<ThreadError: not owner>

It seems like a bug of ext/thread in 1.8.6, and 1.8.7 doesn't
have it.
 
J

Joel VanderWerf

Nobuyoshi said:
Hi,

At Mon, 14 Jul 2008 15:12:16 +0900,
Joel VanderWerf wrote in [ruby-talk:308103]:
The following code generates a ThreadError ("not owner", raised in
unlock_mutex_inner()). However, the ThreadError never gets reported at
the top level (even though my code is re-raising it and
Thread.abort_on_exception = true). A ThreadError that I raise directly
gets reported normally.

For 1.8.6-p114 (Linux), the output is:

#<ThreadError: not owner>

It seems like a bug of ext/thread in 1.8.6, and 1.8.7 doesn't
have it.

I filed a bug report (#275), in case this can be fixed in 1.8.6 for
those of us who are timid about 1.8.7.
 

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

Similar Threads

priority queue using RBTree 2
Thread deadlock 8
Multi Threading 5

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top