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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.182.24.196 with SMTP id w4mr4405335obf.19.1440683555237; Thu, 27 Aug 2015 06:52:35 -0700 (PDT) X-Received: by 10.182.19.198 with SMTP id h6mr65387obe.18.1440683555209; Thu, 27 Aug 2015 06:52:35 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!u8no1029636igq.0!news-out.google.com!nt1ni16570igb.0!nntp.google.com!se8no11314925igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 27 Aug 2015 06:52:34 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=178.193.240.199; posting-account=DQbqYQoAAACn8hHn2LmG2aF7Mhbxl_Lf NNTP-Posting-Host: 178.193.240.199 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Exclusive file access From: ahlan@marriott.org Injection-Date: Thu, 27 Aug 2015 13:52:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:27617 Date: 2015-08-27T06:52:34-07:00 List-Id: Dear All, Obviously I'm misunderstanding something here. I thought that if two processes tried to open the same file for write access then the second process would get an exception. I have a simple example which when compiled using GnatPro 7.3.1 and run under 32-bit Windows XP demonstrates that this is not so. Which then begs the question on how to detect if the file is in use and abort if it is. This should be simple but obviously too complex for my tiny brain. Does anyone know how to do this from Ada (without resorting to the OS directly)? My simple test program is package body Test is package Io renames Ada.Text_IO; procedure Work is The_File : Io.File_Type; begin Io.Open (The_File, Io.Out_File, "Test.Txt"); for Count in Natural'value(Ada.Command_Line.Argument(1)) .. Natural'value(Ada.Command_Line.Argument(2)) loop Io.Put_Line (The_File, "Count =" & Count'img); Io.Put_Line ("Count =" & Count'img); delay 1.0; end loop; Io.Close (The_File); exception when others => Io.Put_Line ("Exception"); end Work; end Test; If I execute this from one process with parameters 1 10 and then when it reaches 8 start the program again from a second process with parameters 3 7 on the same machine, the resultant file is a nice mixture! :-( Count = 3 Count = 4 Count = 5 Count = 6 Count = 7 Count = 6 Count = 7 Count = 8 Count = 9 Count = 10 This is not what I want. I want what the first instance produces and the second instance to fail. Surely nobody would want otherwise ;-) Best wishes, Ahlan