Project

General

Profile

Actions

Bug #275

closed

bug involving condition variables

Added by Anonymous over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
-
[ruby-core:17765]

Description

=begin
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 and Windows OCI), 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). See also ruby-talk:308103.

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 (last=@q.pop)
       return last
     end

     loop do
       @cond.wait(@mutex)
       if (last=@q.pop)
         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
=end

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 15 years ago

  • Assignee set to shyouhei (Shyouhei Urabe)

=begin
[ruby-dev:30809] and [ruby-Bugs-11507] are wrong.
ext/thread needs to be backported from 1.8 head or 1.8.7.
=end

Actions #2

Updated by marcandre (Marc-Andre Lafortune) over 14 years ago

  • Status changed from Open to Closed
  • ruby -v set to -

=begin
Closing this issue since it appears fixed as of ruby 1.8.6 patch 387.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0