Monitor synchronize hangs
-------------------------

                 Key: JRUBY-1239
                 URL: http://jira.codehaus.org/browse/JRUBY-1239
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.0.0
         Environment: ruby 1.8.5 (2007-06-07 rev 3841) [x86-jruby1.0]
            Reporter: Doug Donohoe
            Priority: Blocker


This program (adapted from the pick-axe book) hangs in JRuby.  It works without 
the "synchronize" block in sync_tick.

========================================================
#!/usr/bin/ruby

# multi-threading
require 'monitor'

class Counter
  include MonitorMixin
  attr_reader :count, :scount
  def initialize
    @count = 0
    @scount = 0
    super
  end
  def tick
    @count += 1
  end
  def sync_tick
    synchronize do
      @scount += 1
    end
  end
end

c = Counter.new
threads = []
2.times do
  threads << Thread.new { 1_000.times { c.tick; c.sync_tick }}
end

threads.each { |t| t.join }

puts "Thread counter count=#{c.count}  scount=#{c.scount}"


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to