Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 19362 invoked from network); 7 Jul 2010 09:11:42 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 7 Jul 2010 09:11:42 -0000 Received: (qmail 86888 invoked by uid 500); 7 Jul 2010 09:11:42 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 86639 invoked by uid 500); 7 Jul 2010 09:11:40 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 85711 invoked by uid 99); 7 Jul 2010 09:11:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 09:11:38 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of t.p.ellison@gmail.com designates 209.85.161.49 as permitted sender) Received: from [209.85.161.49] (HELO mail-fx0-f49.google.com) (209.85.161.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jul 2010 09:11:30 +0000 Received: by fxm3 with SMTP id 3so4168500fxm.36 for ; Wed, 07 Jul 2010 02:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type:content-transfer-encoding; bh=AiYDXutMjP7ZYOyDcq2pYacqSrhE8y2tVCuMXRHmayc=; b=RGcKhafRAy0NkrXqE8jgVBoyxdd3SJhtMRPvPUan5pOUEXrKdKSl4C63+nJbLQUm24 Vfgx6IuuMB3cIFnKuQ8nJ/YRLDeaP8RCi/pUfnKGPDOXSltVOwt1Y51zwz9/kQZS3HId fzoW6NBNJn5IMPBaSj8Y+aBvqnqa0gSPNw1Os= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; b=hS/C9egE/7ZSiLN7F8EZK1twDrop7M0Xd8BsX/kc6ffdoyqkk0XU4cT+qFzOWvyIJF MMzhjqXw2NK/Y+sWMO7Z6TqUoQ+kgGU8B4HURZu10UxiwPHaHbp2ZJZ2hcZyMgVxllyP 65tOX6pSwBqtq3xwNtQwnrCgSOkHANtO/gtxU= Received: by 10.223.108.72 with SMTP id e8mr5423460fap.8.1278493870155; Wed, 07 Jul 2010 02:11:10 -0700 (PDT) Received: from [9.20.183.74] (gbibp9ph1--blueice3n1.emea.ibm.com [195.212.29.83]) by mx.google.com with ESMTPS id q24sm14038706faa.42.2010.07.07.02.11.09 (version=SSLv3 cipher=RC4-MD5); Wed, 07 Jul 2010 02:11:09 -0700 (PDT) Message-ID: <4C344478.7070200@gmail.com> Date: Wed, 07 Jul 2010 10:10:16 +0100 From: Tim Ellison User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: dev@harmony.apache.org Subject: [classlib][luni] creating temporary files (was: Re: svn commit: r960424 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/File.java) References: <20100705030517.1F57223889E5@eris.apache.org> <201007061356.o66Du8Md001843@d06av02.portsmouth.uk.ibm.com> In-Reply-To: X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 06/Jul/2010 15:49, Jesse Wilson wrote: > On Sun, Jul 4, 2010 at 8:05 PM, wrote: > >> File.counter could be accessed by multiple threads, so use >> AtomicInteger to make sure each thread using different int >> value to create temp file. > > Is this a sufficient fix for the problem? The file system may be shared by > multiple concurrently-executing VMs. Coordinating access to temp files > within a single VM doesn't prevent other processes from grabbing the same > file names. > > A more robust solution might involve including the VM's process ID in the > filename. Or perhaps some kind of create-and-test protocol in a loop. I'm confused ... the code I'm looking at in File (before Regis' changes) do have the create in a loop. Not showing some checking etc, it says, public static File createTempFile(String prefix, String suffix, File directory) throws IOException { File result; do { result = genTempFile(prefix, newSuffix, tmpDirFile); } while (!result.createNewFile()); return result; } the genTempFile is having a good guess at creating a unique name, in pseudo code: private static File genTempFile(String prefix, String suffix, File directory) { if atomic counter is not set, initialize to a random number return File (dir, prefix + counter.getAndIncrement() + suffix); } and the "while (!result.createNewFile())" loops while the creation reports the file exists. So what was the original problem that needed fixing? Multiple threads should have a different value for the 'counter' and multiple VMs are either separated by the random number initialization, or have to spin on a test and re-gen a name if they collide. > On Tue, Jul 6, 2010 at 6:56 AM, Mark Hindess wrote: > >> This breaks the build for the IBM VME (from developerWorks). Since they >> don't have a sun.misc.Unsafe, so the AtomicInteger can't be resolved. > > If VME is to stay modern, they're going to need to support > java.util.concurrent. I don't think Harmony should provide a > lowest-common-denominator class library; supporting systems that don't have > j.u.c is an unnecessary handicap. Agreed. As shown above this code already uses concurrent utilities in the existing algorithm anyways. > Particularly since they can implement AtomicInteger using less efficient > concurrency primitives. There's even a full > backportthat could close some > gaps if the standard java.util.concurrent isn't > feasible for their VM. We should just assume that we can use concurrent. VMs will have to support it as they see fit. Regards, Tim