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 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: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Exclusive file access Date: Thu, 27 Aug 2015 11:29:56 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <8cbeb0d0-0c55-4502-875b-a0fe0d23e13d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Thu, 27 Aug 2015 18:28:12 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ee44d3db9c41f5ad88d7e8e8f0268f05"; logging-data="31978"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lVn9dScJb6pD8rTQuVoY4WHQqo32aqvM=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 In-Reply-To: <8cbeb0d0-0c55-4502-875b-a0fe0d23e13d@googlegroups.com> Cancel-Lock: sha1:zDCFr3LZ9EypeXYVvmIOGJHSYfc= X-Enigmail-Draft-Status: N1110 Xref: news.eternal-september.org comp.lang.ada:27623 Date: 2015-08-27T11:29:56-07:00 List-Id: On 08/27/2015 08:15 AM, ahlan@marriott.org wrote: > If I try to open the file twice within the same process then it works as > expected but NOT if the file is opened twice from different processes. What happens when 2 or more processes try to open the same file for writing is dependent on the OS. Clearly on Windows there are multiple ways to open a file, one of which allows multiple processes to open the same file, and this is the way that GNAT uses. GNAT would appear to detect multiple openings within the same program in a manner not dependent on the features of the OS. The GNAT RM indicates that Create and Open map onto a call to the C function fopen with certain parameters; you could try creating a C version of your example using the fopen parameters the RM indicates GNAT uses and see if it exhibits the same behavior. The method Ada provides for dealing with such external factors in dealing with files is the Form parameter to Create and Open. It appears that GNAT does not provide any way to deal with this situation through the Form parameter. Using the Form string "shared=no" in your example doesn't affect the behavior. Another way to get the behavior you're looking for is to use lock files, and GNAT offers a way to deal with them. > I can get it to work under Windows if I do my own IO using the windows API > directly but of course that is not exactly portable and rather defeats the > point of having Ada.Text_Io. When neither the language nor the implementation provides a way to get the OS to do what you want, you have to provide the desired functionality yourself. A package providing the required operations would have a non-portable body, but would only require replacing the body to port to a different platform. > Is this a Gnat bug? Since the ARM doesn't specify what happens in this case, leaving it up to the OS, and the OS clearly allows GNAT's behavior, it does not appear to be a GNAT error. However, since you have GNAT Pro, if you also have a support contract with AdaCore, you could ask them how to achieve what you want. -- Jeff Carter "Have you gone berserk? Can't you see that that man is a ni?" Blazing Saddles 38