diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-28 18:11:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-08-28 18:11:37 +0000 |
commit | 01ab317751016323d7bf18dca8f9f5a343b17330 (patch) | |
tree | 9c47c204be4887774b1f0d72f1985241a9a6b001 /lib | |
parent | 8365f5f9255397aaaa9ab2a000e2c061c60147bc (diff) | |
download | ruby-01ab317751016323d7bf18dca8f9f5a343b17330.tar.gz ruby-01ab317751016323d7bf18dca8f9f5a343b17330.tar.xz ruby-01ab317751016323d7bf18dca8f9f5a343b17330.zip |
* lib/tempfile.rb (Tempfile#make_tmpname): removed thread race
condition.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/tempfile.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/tempfile.rb b/lib/tempfile.rb index 4061b170a..46164e8b9 100755 --- a/lib/tempfile.rb +++ b/lib/tempfile.rb @@ -125,12 +125,8 @@ class Tempfile < DelegateClass(File) # # === Exceptions # - # Under rare circumstances, this constructor can raise an instance of - # Tempfile::CreationError. This could happen if a large number - # of threads or processes are simultaneously trying to create temp files - # and stepping on each others' toes. If Tempfile.new cannot find - # a unique filename within a limited number of tries, then it will raise - # this exception. + # If Tempfile.new cannot find a unique filename within a limited + # number of tries, then it will raise an exception. def initialize(basename, *rest) # I wish keyword argument settled soon. if opts = Hash.try_convert(rest[-1]) @@ -191,7 +187,8 @@ class Tempfile < DelegateClass(File) end t = Time.now.strftime("%Y%m%d") - path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}" + th = Thread.current.object_id + path = "#{prefix}#{t}-#{$$}-#{th.to_s(36)}-#{rand(0x100000000).to_s(36)}-#{n}#{suffix}" end private :make_tmpname |