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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: =?UTF-8?B?QmrDtnJuIEx1bmRpbg==?= Newsgroups: comp.lang.ada Subject: Re: Exclusive file access Date: Sun, 06 Sep 2015 21:52:06 +0200 Organization: A noiseless patient Spider Message-ID: References: <6725e7d9-eb8e-49b0-985d-9c1b1bbd6fd8@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 6 Sep 2015 19:50:17 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8345e58a26fd519be507aa0186b6063e"; logging-data="2366"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iY9cxrd7QEPTNv2UmWT1M" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.8.0 In-Reply-To: Cancel-Lock: sha1:V9yw5+SKaiuuQqPSVg1x609UyTE= Xref: news.eternal-september.org comp.lang.ada:27719 Date: 2015-09-06T21:52:06+02:00 List-Id: On 2015-09-06 19:38, brbarkstrom@gmail.com wrote: > On Saturday, September 5, 2015 at 11:56:28 AM UTC-4, björn lundin wrote: >> >>> I have no idea about Linux but it is perfectly possible under Windows. >>> However this doesn't stop people (including Microsoft) from creating lock >>> files that then sometimes get left behind when a program crashes >>> rendering the file locked forever! >>> So the presence of lock files doesn't mean that the opsys can't lock >> exclusively. >> >> That is why you do not want to use gnat.lockfiles, (at least on linux) >> but instead use somthing like linux' lockf. >> >> If the process holding the lock gets killed, (even by kill -kill) >> the kernel (or something) releases the lock. >> No stale lockfiles. >> >> >> -- >> Björn > > I have been debugging a concurrent Ada program (on Windows XP, but I > expect the GNAT GPL would work the same on Linux). We are talking about different things. The op said he had *several processes*. Not one process with several tasks. My posting above is directed to the case with several processes, not several tasks. Say you have a program that should run almost all the time. But when it experiences external trouble (network down), its easier to just exit the program, and have a scheduler to restart it. (crude but simple and good enough in my case) Now, the scheduler needs find out if one instance is running or not. More than one instance is no good. The program then uses lockf to lock a file exclusively at startup. The scheduler runs once a minute and tries to lock that same file. If failure - the process runs and that is it. If success - release the lock, and restart the process. Also, if the process is restarted by mistake, it will fail to lock the file, and exit. There is already an instance running. Has nothing to do with tasks. Its like opening the file with notepad and word at the same time. -- -- Björn