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
At Fri, 26 Mar 2004 23:19:28 +0900,
Robert Klemme wrote in [ruby-talk:95917]:
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.
Yes if it is without `o’ option or in recent version.
At Fri, 26 Mar 2004 23:19:28 +0900,
Robert Klemme wrote in [ruby-talk:95917]:
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.
Yes if it is without `o’ option or in recent version.
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================