Issue Type: Bug Bug
Affects Versions: JRuby 1.7.3, JRuby 1.6.7
Assignee: Thomas E Enebo
Created: 17/May/13 10:58 AM
Description:

I've found that regexp match is not thread-safe when called in a lambda, returning mismatched values (1.8 or 1.9 ruby mode).

A sample rspec code:

TEST_REGEXP=/MA-(.*)/
TEST_REGEXP_LAMBDA=lambda { |prefix,i|  m=("MA-#{prefix}#{i}".match(TEST_REGEXP));m[1] }

describe "Bugs:" do
  it "regexp not thread safe in lambda call" do
    threads=[]
    prefix="20130501"
    n=100000
    err=0
    res={}
    safe_res={}
    expected_res={}
    mutex=Mutex.new
    (nt=3).times do |i|
      expected_res["#{prefix}#{i}"]=n
      threads << Thread.new do
        n.times do
         begin
           # safe call
           m=("MA-#{prefix}#{i}".match(TEST_REGEXP))
           mutex.synchronize { safe_res[m[1]]||=0; safe_res[m[1]]+=1 }

           # not safe call
           r=TEST_REGEXP_LAMBDA.call(prefix,i)
           mutex.synchronize { res[r]||=0; res[r]+=1 }
         rescue Exception => e
           mutex.synchronize { err+=1 }
         end
        end
      end
    end
    threads.shift.join until threads.empty?
    err.should == 0
    safe_res.should == expected_res
    res.should == expected_res
  end
end
Environment: jruby 1.6.7 (ruby-1.9.2-p312) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_17) [linux-amd64-java]
Project: JRuby
Priority: Minor Minor
Reporter: Giovanni Cristelli
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
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