Compare-and-Swap on top of POSIX compatible file system objects

There are several operations that POSIX-compatible operating systems can perform atomically with file system objects (files and folders). Here is a list of these supposedly atomic operations :

  • rename or move file or folder
  • create hardlink
  • create a symbolic link
  • create a folder
  • create and open an empty file

Is it possible to build a Compare-and-Swap algorithm for managing a file based on these operations?

Suppose we have several processes that perform parallel read / write in one file. The file is characterized by its revision. Suppose that adding changes is added to the file name, and there is a symbolic link to the file that processes can use to read it. Processes cannot (for some reason) synchronize with mutexes, semaphores, etc., but they can create auxiliary files and folders. Can they make modifications to the Compare-and-Swap file based on the changes (create a new file, create and rename a symbolic link) in the sense that if several processes change it at the same time, one will succeed, and the rest will fail with some error code ?

The algorithm must be resistant to the sudden termination of any processes at any stage of the algorithm.

+4
2

, .

, , , . .

  • .
  • , - .
  • . , .
  • , . - .

, . = P

+2

fcntl (2) , -. flock (1), . (flock (1) util-linux-ng.)

flock (2) POSIX, fcntl (2). , flock (1) fcntl (2) (, NFS).

, :

    • fcntl() , , . , mutex.
  • 2. fcntl , .
  • 2b. fcntl , .
    1. fcntl .

, fcntl (2), , , .

, fcntl (2) , .

+2

All Articles