From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,892f841b317b302e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!204.71.34.3!newsfeed.cwix.com!news.binc.net!kilgallen From: Kilgallen@SpamCop.net (Larry Kilgallen) Newsgroups: comp.lang.ada Subject: Re: Format string bugs & race conditions Date: 17 Oct 2004 12:28:57 -0500 Organization: LJK Software Message-ID: References: <1c2f5137.0410160128.7ef88436@posting.google.com> NNTP-Posting-Host: eisner.encompasserve.org X-Trace: grandcanyon.binc.net 1098034138 5724 192.135.80.34 (17 Oct 2004 17:28:58 GMT) X-Complaints-To: abuse@binc.net NNTP-Posting-Date: Sun, 17 Oct 2004 17:28:58 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:5372 Date: 2004-10-17T12:28:57-05:00 List-Id: In article , Marius Amado Alves writes: >> /* If lockfile already exists, wait until it goes away. */ >> while((p = fopen("lockfile", "r"))) { >> fclose(p); >> sleep(1); >> } >> /* (race) */ >> p = fopen("lockfile", "w"); >> /* Access the stuff which lockfile is supposed to protect from >> * multiple access. But of course it doesn't. */ >> fclose(p); >> remove("lockfile"); >> >> Ada just makes it easier to implement this bug within a single >> instance of the executable. > > No. Using files for locks is equally easy to implement and equally buggy > in any language. And that might be "not buggy at all", depending on _how_ you use files. Regardless of programming language*, when one calls the VMS system service SYS$CREATE with the FAB$V_CIF option a status code of RMS$_CREATED indicates that the file was created by this process. If not, it is time to try again for the example above. Of course opening a file is a costly synchronization mechanism which should only be used in cases where the cost will be dwarfed by the cost of the operation being protected. * As usual Ada programmers use slightly different symbol names since Ada does not allow "$" in symbols.