https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112012-01-24T10:06:20ZRuby Issue Tracking SystemRuby master - Bug #5925: Lazy initialization is not thread safe.https://redmine.ruby-lang.org/issues/5925?journal_id=234122012-01-24T10:06:20Znahi (Hiroshi Nakamura)nakahiro@gmail.com
<ul></ul><p>=begin<br>
I think the author expected that Hash#replace is thread-safe, and it surely is in CRuby. (see rescue for double freeze)</p>
<p>TBLENCWWWCOMP_ = {} # :nodoc:<br>
...<br>
def self.encode_www_form_component(str)<br>
if TBLENCWWWCOMP_.empty?<br>
tbl = {}<br>
256.times do |i|<br>
tbl[i.chr] = '%%%02X' % i<br>
end<br>
tbl[' '] = '+'<br>
begin<br>
TBLENCWWWCOMP_.replace(tbl)<br>
TBLENCWWWCOMP_.freeze<br>
rescue<br>
end<br>
end<br>
...</p>
<p>Someone can rewrite this with singleton.rb. Challenger?<br>
=end</p> Ruby master - Bug #5925: Lazy initialization is not thread safe.https://redmine.ruby-lang.org/issues/5925?journal_id=234132012-01-24T10:53:15ZAnonymous
<ul></ul><p>On Tue, Jan 24, 2012 at 10:06:21AM +0900, Hiroshi Nakamura wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Lazy initialization is not thread safe. (Closed)" href="https://redmine.ruby-lang.org/issues/5925">#5925</a> has been updated by Hiroshi Nakamura.</p>
<p>=begin<br>
I think the author expected that Hash#replace is thread-safe, and it surely is in CRuby. (see rescue for double freeze)</p>
<p>TBLENCWWWCOMP_ = {} # :nodoc:<br>
...<br>
def self.encode_www_form_component(str)<br>
if TBLENCWWWCOMP_.empty?<br>
tbl = {}<br>
256.times do |i|<br>
tbl[i.chr] = '%%%02X' % i<br>
end<br>
tbl[' '] = '+'<br>
begin<br>
TBLENCWWWCOMP_.replace(tbl)<br>
TBLENCWWWCOMP_.freeze<br>
rescue<br>
end<br>
end<br>
...</p>
<p>Someone can rewrite this with singleton.rb. Challenger?</p>
</blockquote>
<p>Why don't we just do it when the file is required? I know it adds<br>
overhead when the file is required, but that seems minimal when compared<br>
to the runtime savings.</p>
<p>I made a patch here:</p>
<p><a href="https://gist.github.com/1667280" class="external">https://gist.github.com/1667280</a></p>
<p>--<br>
Aaron Patterson<br>
<a href="http://tenderlovemaking.com/" class="external">http://tenderlovemaking.com/</a></p> Ruby master - Bug #5925: Lazy initialization is not thread safe.https://redmine.ruby-lang.org/issues/5925?journal_id=234142012-01-24T11:52:11Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r34364.<br>
Xuân, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>lib/uri/common.rb (URI.encode_www_form_component): initialize on<br>
requiring to support JRuby, which runs parallel multithreads.<br>
<a href="/issues/5925">[ruby-core:42222]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Lazy initialization is not thread safe. (Closed)" href="https://redmine.ruby-lang.org/issues/5925">#5925</a>]</p>
</li>
<li>
<p>lib/uri/common.rb (URI.decode_www_form_component): initialize on</p>
</li>
</ul> Ruby master - Bug #5925: Lazy initialization is not thread safe.https://redmine.ruby-lang.org/issues/5925?journal_id=259462012-04-17T08:27:16Zthomasinareckers (Thomas Inareckers)thomasinareckers863@hotmail.com
<ul></ul><p>Thanks Aaron<br>
<a href="http://remotedatabackuptips.posterous.com/" class="external">http://remotedatabackuptips.posterous.com/</a></p>