Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-request From: ontek!banzai!mikey@uunet.uu.net (Mike Lee) Newsgroups: comp.sys.sun Subject: Re: Sys V sizes, shared libs etc Message-ID: <8902011835.AA14003@banzai.ontek.com> Date: 9 Feb 89 04:18:42 GMT Sender: usenet@rice.edu Organization: Sun-Spots Lines: 50 Approved: Sun-Spots@rice.edu Original-Date: Wed, 1 Feb 89 10:35:28 PST X-Sun-Spots-Digest: Volume 7, Issue 146, message 4 of 8 Yikes, Martin McKendry asked several of the kind of questions one asks before designing a large system. I can only answer one of them: > o) Are semaphores the only appropriate technique for implementing > mutual exclusion on small objects? ... It seems like a lot of > overhead to allocate one semaphore per record. Yes indeedy doodie it's a lot of uberkopf. What works better is to use just one system semaphore to control access to no-touchy bits, which are one to a record. When a process wants to exclude other processes from a record it should do this: a. get the one semaphore b. read in the record (or whatever structure stores the no touchy bit) c. test and set the no-touchy bit - if das bit is already set, release main semaphore and retry later - else set it and continue d. write out no-touchy bit e. fflush (and sync) to make sure secondary storage is updated f. release main semaphore so other records can be locked g. perform whatever function required the mutual exclusion in the 1st place h. reset the no-touchy bit i. write out bit and record, fflushing and syncing along the way j. lather, rinse, repeat You almost have to use this method, because on most systems the total number of semaphores is fixed and quite small, usually < 100. If the records are stored in shared memory rather than disk, you can leave out the fflush and sync stuff. This algorithm is not original on my part by any means, and neither I nor my employer stand behind it in anyway. Buy the weigh, has anyone noticed lockf (NOT flock) having problems? When I axe for the lock on a file on an NFS file system it never gives it to me, even though I know I'm the only one using the file. Needles two say, this is ultra-irritating. It works fine on local file systems. Glad that you got it made, Mikey Lee Ontek Corp PS: Dear wnl, outlaw those insipid ":-)" smiley faces now! [[ Okay. I won't use that smiley face anymore! (-: --wnl ]] VOX: 1-714-768-0301 UUCP: uunet!ontek!mikey (not sure about that - seems too simple) USPS: 22951 Mill Creek Road, Laguna Hills CA 92653