home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.sgi
- Path: sparky!uunet!pipex!doc.ic.ac.uk!cc.ic.ac.uk!imperial.ac.uk!vulture
- From: vulture@imperial.ac.uk (Thomas Sippel - Dau)
- Subject: Re: what is the difference between shared and exclusive file locks?
- Message-ID: <1992Dec16.190307.1894@cc.ic.ac.uk>
- Sender: vulture@carrion.cc.ic.ac.uk (Thomas Sippel - Dau)
- Nntp-Posting-Host: cscgc
- Reply-To: cmaae47@imperial.ac.uk
- Organization: Imperial College of Science, Technology and Medicine
- References: <1992Dec15.131211.10307@wl.com>
- Distribution: usa
- Date: Wed, 16 Dec 92 19:03:06 GMT
- Lines: 52
-
- In article <1992Dec15.131211.10307@wl.com>, agrafiot@wl.com (Dimitris Agrafiotis) writes:
-
- - Can somebody explain to me what the difference between shared and
- - exclusive locks is (LOCK_SH/LOCK_EX in flock()).
-
- Shared file locks prevent other processes from writing the file, but they
- can still read it.
-
- Exclusive locks should prevent other processes from reading the file, as
- the locking process is about to change it.
-
- Thus when you want to modify a file, you should
-
- o obtain a shared lock
- o read some information
- o release the lock
- o modify the information as desired
-
- o obtain an exclusive lock
- o re-read the information
- o compare it with the previously read one
- o if the compare fails but the differences can be consolidated, do so
- o if the differences can not be consolidated abort the update
- o if the compare is ok write the information back
- o release the lock
-
- The first lock ensures nobody else actually modifies what you read while
- you read it, the second lock stops other people reading information which
- will soon be out of date.
-
- The two stage process is necessary when the modification takes a significant
- time, for example when fields are updated in terminal interactions. It could
- be that the user is shot without finding time to close the transaction
- properly, leaving you with a database you can no longer modify until you
- clear the lock manually or reboot the system.
-
- In client server environments there is often a specific server process that
- locks the file exclusively. All other users have to talk to the server to
- get read or modify access to the data, and the server serialises all the transactions.
-
- This way a definciency of the unix system (only file locks, no record
- locks) has been turned into a must-have asset - support for client-server
- environments and all that.
-
- Thomas
-
- --
- *** This is the operative statement, all previous statements are inoperative.
- * email: cmaae47 @ ic.ac.uk (Thomas Sippel - Dau) (uk.ac.ic on Janet)
- * voice: +44 71 589 5111 x4937 or 4934 (day), or +44 71 823 9497 (fax)
- * snail: Imperial College of Science, Technology and Medicine
- * The Center for Computing Services, Kensington SW7 2BX, Great Britain
-