Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!jarthur!bridge2!3comvax!tymix!cirrusl!sunstorm!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.unix.wizards Subject: Re: Is HDB locking safe? Message-ID: <2309@cirrusl.UUCP> Date: 25 Aug 90 04:40:49 GMT References: <577@oglvee.UUCP> <4024@rtifs1.UUCP> <18500@rpp386.cactus.org> <+7C5OFD@xds13.ferranti.com> Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 32 >I guess creating a second lock file to be held while deleting the first >would work. Our in-house software does file locking, to create a lock file L, like this: exlock(L); create L; exunlock(L); /* critical section here */ exlock(L); delete L; exunlock(L); The definition of exlock(L) is: create a lock file called L|lock, looping with sleep(5) several times if necessary; if creation fails, report a very serious error and exit process. The definition of exunlock(L) is: delete L|lock; if nonexistent or can't be deleted, report a very serious error and exit process. Barring a system or process crash during the very brief interval that L|lock exists, the above scheme is very robust. -- Rahul Dhesi UUCP: oliveb!cirrusl!dhesi