require 'uri'
@results = []
1000.times { Thread.new { @results << Regexp::Parser.parse(URI.regexp) } }
@results.map(&:strfre).uniq.count # => 10 or so (should be 1)
I guess this is due to the "instance" variables on the Scanner, Lexer and Parser classes existing on the classes themselves and thus being shared among executions. If so, it can be easily fixed by making their class methods into instance methods. E.g. for Scanner:
def self.scan(input_object, &block)
new.scan(input_object, &block)
end
def scan(input_object, &block)
@literal, top, stack = nil, 0, []
# ...
end
test case:
I guess this is due to the "instance" variables on the Scanner, Lexer and Parser classes existing on the classes themselves and thus being shared among executions. If so, it can be easily fixed by making their class methods into instance methods. E.g. for Scanner: