|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-08-09 12:08:35
I need the ability to do interprocess synchronization through file
locking, c.f. Java.File.createNewFile and Java.File.deleteOnExit:
--- createNewFile public boolean createNewFile() throws IOException Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. This method, in combination with the deleteOnExit() method, can therefore serve as the basis for a simple but reliable cooperative file-locking protocol. Returns: true if the named file does not exist and was successfully created; false if the named file already exists Throws: IOException - If an I/O error occurred SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.io.FileDescriptor) method denies write access to the file deleteOnExit public void deleteOnExit() Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates. Deletion will be attempted only for normal termination of the virtual machine, as defined by the Java Language Specification (12.9). Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care. Throws: SecurityException - If a security manager exists and its SecurityManager.checkDelete(java.lang.String) method denies delete access to the file --- On Posix, the first one would be done with open(..., O_CREAT | O_EXCL) and the second, I suppose, would be done with a terminate handler. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk