From: Robert Klemme Date: 2004-03-26T23:19:28+09:00 Subject: Save to use const Regexp in several threads? Hi all, out of curiosity: is it safe to define a global constant regular expression and use that concurrently from several threads? I put together a test script that seems to indicate it is safe, but a test is no definite answer. Kind regards robert #!/usr/bin/ruby require 'set' RX = /./ threads = [] def create(s) Thread.new(s) do |str| set = Set.new str.scan(RX) do |m| set << m Thread.pass end # set should contain more than one entry if # it is not safe p set.to_a end end %w{a b c d e f}.each do |c| threads << create(c * 1000) end threads.each {|th| th.join}