lundi 28 décembre 2015

File locking on Linux without fcntl nor flock

Problem:

In a linux application, I am required to use file locks. The files I need to lock are in an unknown number. Therefore, they may be either on disk or on a NFS.

They are accessed by multiple threads and multiple processes at a time. I need to lock the whole file when a lock is needed.

I already thought deeply about flock and fcntl but:

  1. flock is system bound and doesn't work over NFS. If it does it must use fcntl (2)
  2. fcntl can't block across threads, only processes with differents PIDs

So is there out there a way to lock a file without boost that will do the trick or a way to create a file that fails on file existence to make a manual filelock ?

Aucun commentaire:

Enregistrer un commentaire