Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.0.0
-
Fix Version/s: JRuby 1.0.1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:ruby 1.8.5 (2007-06-07 rev 3841) [x86-jruby1.0]
-
Testcase included:yes
Description
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}"
Test file.