From: Aaron Patterson Date: 2012-01-24T10:50:29+09:00 Subject: [ruby-core:42224] Re: [ruby-trunk - Bug #5925] Lazy initialization is not thread safe. --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jan 24, 2012 at 10:06:21AM +0900, Hiroshi Nakamura wrote: >=20 > Issue #5925 has been updated by Hiroshi Nakamura. >=20 >=20 > =3Dbegin > I think the author expected that Hash#replace is thread-safe, and it sure= ly is in CRuby. (see rescue for double freeze) >=20 > TBLENCWWWCOMP_ =3D {} # :nodoc: > ... > def self.encode_www_form_component(str) > if TBLENCWWWCOMP_.empty? > tbl =3D {} > 256.times do |i| > tbl[i.chr] =3D '%%%02X' % i > end > tbl[' '] =3D '+' > begin > TBLENCWWWCOMP_.replace(tbl) > TBLENCWWWCOMP_.freeze > rescue > end > end > ... >=20 > Someone can rewrite this with singleton.rb. Challenger? Why don't we just do it when the file is required? I know it adds overhead when the file is required, but that seems minimal when compared to the runtime savings. I made a patch here: https://gist.github.com/1667280 --=20 Aaron Patterson http://tenderlovemaking.com/ --MGYHOYXEY6WxJCY8 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJPHg5dAAoJEJUxcLy0/6/G30EH+QEK735BvJkH63CPoidzzaIs /5LPgrrz+BMXQSj2PnLSI9tNGeW93G0sXdegR28QkJlEK/W4vjuwKAz+IDk/JOyW Hf4YTyzJ+LX1Y8LHY3LVrDrUwNrhgKqruGntwd8g5/LBOM9JPp9UA4PDcXM1bvsH rH5W1UcSAoNeYLSR0mkuG/Wl/0ohc3bFQd7G/rm3rezNR19bVjMEFN/JAIyRi4DA cp/Cmg1fMmx+bctat5N3+UUvOGmNr3SRuORupXPMa5bnbW7jJlElAMzvdSM++Vuf K/9nHc6+8uDtiNlNmjgs/uiaDrhDjfZzDowvvv7QxaDv81JNZQvL4S3IO9nTXCE= =YDTP -----END PGP SIGNATURE----- --MGYHOYXEY6WxJCY8--