Path: utzoo!utgpu!water!watmath!clyde!burl!codas!killer!jfh From: jfh@killer.UUCP (The Beach Bum) Newsgroups: comp.unix.wizards Subject: Re: Unix vs. OS/2 (was RE: Pournelle on Unix) Summary: Don't work. There is a race someplace ;-) Message-ID: <2775@killer.UUCP> Date: 11 Jan 88 01:06:18 GMT References: <11156@brl-adm.ARPA> <448@minya.UUCP> Organization: Big "D" Home for Wayward Hackers Lines: 30 In article <448@minya.UUCP>, jc@minya.UUCP (John Chambers) writes: > In article <11156@brl-adm.ARPA>, GUTHERY%ASC%sdr.slb.com@RELAY.CS.NET (guthery%asc@sdr.slb.com) writes: > I'll just point out that every Unix I've ever seen has > systemwide semaphores. They just aren't called that. Try: > if ((l = creat("/usr/spool/locks/",0)) { > ... > [Critical section] > ... > unlink("/usr/spool/locks/"); > } else { > [Didn't get semaphore] > } > It worked on BRL Version 6, and it still works, even on SunOS. I understand there is an old race in the V7 and System III kernels that causes this to not work reliably. Also, it doesn't work at all if root executes the code as root will just re-create the file AND return success to boot. [ isn't that special? ;-) ] For System V, use the three argument form of open(2) and OR in the O_EXCLUDE flag. This insures ;-) ;-) that the file does not exist before trying the open. Label me paranoid, but, I prefer to stick an access() in the if() before the open(). Just in case ... - John. -- John F. Haugh II SNAIL: HECI Exploration Co. Inc. UUCP: ...!ihnp4!killer!jfh 11910 Greenville Ave, Suite 600 "Don't Have an Oil Well? ... Dallas, TX. 75243 ... Then Buy One!" (214) 231-0993 Ext 260