How should one implement reader/writer locks on files?
> How should one implement reader/writer locks on files? > The locks should work accross threads and processes. The only way to lock “a file” is to use the fcntl() file locking functions. Check your man page. HOWEVER, there’s a big IF… these locks are held by the PROCESS, not by the THREAD. You can’t use them to control access between multiple threads within a process. If you are interested in a mechanism outside the file system, you could use UNIX98 read/write locks, with the pshared option to make them useful between processes (when placed in shared memory accessible to all the processes). However, UNIX98 read/write locks are not currently available on most UNIX implementations, so you’d have to wait a while. Of course you’d have to work out a way to communicate your shared memory section and the address of the read/write lock(s) to all of the processes interested in synchronizing. Also, while there are ways to make fcntl() locking mandatory instead of advisory (at least, on most s