comp.lang.ada
 help / color / mirror / Atom feed
* Attempting to create file i task
@ 2021-03-17 12:39 reinert
  2021-03-17 12:49 ` J-P. Rosen
  2021-03-17 15:20 ` Shark8
  0 siblings, 2 replies; 16+ messages in thread
From: reinert @ 2021-03-17 12:39 UTC (permalink / raw)


Hello,

Assume task A starts subsequentially two times sub-sequentially (but not overlapping in time). It creates and closes a file:

  define
      my_file : File_Type;
  begin
     Create  (File => my_file, Mode => Out_File, Name => my_file_name);
     ..some statements...
     Close(my_file);
  end;

I now have the strange experience that task A overwrites the file
created the first time?  Any idea where to look for the error?

reinert

  

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 12:39 Attempting to create file i task reinert
@ 2021-03-17 12:49 ` J-P. Rosen
  2021-03-17 14:17   ` reinert
  2021-03-17 14:18   ` AdaMagica
  2021-03-17 15:20 ` Shark8
  1 sibling, 2 replies; 16+ messages in thread
From: J-P. Rosen @ 2021-03-17 12:49 UTC (permalink / raw)


Le 17/03/2021 à 13:39, reinert a écrit :
> Hello,
> 
> Assume task A starts subsequentially two times sub-sequentially (but not overlapping in time). It creates and closes a file:
> 
>    define
>        my_file : File_Type;
>    begin
>       Create  (File => my_file, Mode => Out_File, Name => my_file_name);
>       ..some statements...
>       Close(my_file);
>    end;
> 
> I now have the strange experience that task A overwrites the file
> created the first time?  Any idea where to look for the error?
> 
Create always "creates" the file, i.e. if it exists, it is overwritten. 
What would you expect?

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 12:49 ` J-P. Rosen
@ 2021-03-17 14:17   ` reinert
  2021-03-17 14:21     ` reinert
                       ` (3 more replies)
  2021-03-17 14:18   ` AdaMagica
  1 sibling, 4 replies; 16+ messages in thread
From: reinert @ 2021-03-17 14:17 UTC (permalink / raw)


onsdag 17. mars 2021 kl. 13:49:23 UTC+1 skrev J-P. Rosen:
> Le 17/03/2021 à 13:39, reinert a écrit : 
.......
> >
> Create always "creates" the file, i.e. if it exists, it is overwritten. 
> What would you expect? 

Sorry to be imprecise. The files for two instances of the task have different names. 
For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten.
When I run the two task separately (with various tasks between) then "name_1" is not overwritten.

reinert


> 
> -- 
> J-P. Rosen 
> Adalog 
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX 
> Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 
> http://www.adalog.fr

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 12:49 ` J-P. Rosen
  2021-03-17 14:17   ` reinert
@ 2021-03-17 14:18   ` AdaMagica
  2021-03-17 14:33     ` Jeffrey R. Carter
  2021-03-17 14:34     ` reinert
  1 sibling, 2 replies; 16+ messages in thread
From: AdaMagica @ 2021-03-17 14:18 UTC (permalink / raw)


Create with mode Append

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:17   ` reinert
@ 2021-03-17 14:21     ` reinert
  2021-03-17 14:34     ` Jeffrey R. Carter
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 16+ messages in thread
From: reinert @ 2021-03-17 14:21 UTC (permalink / raw)


More info: I use Debian 10.8 (buster) updated. gnat-8.

reinert

onsdag 17. mars 2021 kl. 15:17:23 UTC+1 skrev reinert:
> onsdag 17. mars 2021 kl. 13:49:23 UTC+1 skrev J-P. Rosen: 
> > Le 17/03/2021 à 13:39, reinert a écrit :
> .......
> > > 
> > Create always "creates" the file, i.e. if it exists, it is overwritten. 
> > What would you expect?
> Sorry to be imprecise. The files for two instances of the task have different names. 
> For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten. 
> When I run the two task separately (with various tasks between) then "name_1" is not overwritten. 
> 
> reinert
> > 
> > -- 
> > J-P. Rosen 
> > Adalog 
> > 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX 
> > Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 
> > http://www.adalog.fr

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:18   ` AdaMagica
@ 2021-03-17 14:33     ` Jeffrey R. Carter
  2021-03-17 14:34     ` reinert
  1 sibling, 0 replies; 16+ messages in thread
From: Jeffrey R. Carter @ 2021-03-17 14:33 UTC (permalink / raw)


On 3/17/21 3:18 PM, AdaMagica wrote:
> Create with mode Append

also overwrites an existing file.

-- 
Jeff Carter
"In our experiments, the [Ada] compile[r] was able to find not
just typographical errors, but also conceptual errors in the
development of the code."
Scott and Bagheri
161

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:18   ` AdaMagica
  2021-03-17 14:33     ` Jeffrey R. Carter
@ 2021-03-17 14:34     ` reinert
  2021-03-17 14:47       ` AdaMagica
  1 sibling, 1 reply; 16+ messages in thread
From: reinert @ 2021-03-17 14:34 UTC (permalink / raw)


onsdag 17. mars 2021 kl. 15:18:11 UTC+1 skrev AdaMagica:
> Create with mode Append

"Mode => Append_File" only makes the files to "mix".

reinert

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:17   ` reinert
  2021-03-17 14:21     ` reinert
@ 2021-03-17 14:34     ` Jeffrey R. Carter
  2021-03-17 15:01     ` Dmitry A. Kazakov
  2021-03-17 16:19     ` J-P. Rosen
  3 siblings, 0 replies; 16+ messages in thread
From: Jeffrey R. Carter @ 2021-03-17 14:34 UTC (permalink / raw)


On 3/17/21 3:17 PM, reinert wrote:
> 
> Sorry to be imprecise. The files for two instances of the task have different names.
> For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten.
> When I run the two task separately (with various tasks between) then "name_1" is not overwritten.

Then you will have to post code that actually reproduces the problem.

-- 
Jeff Carter
"In our experiments, the [Ada] compile[r] was able to find not
just typographical errors, but also conceptual errors in the
development of the code."
Scott and Bagheri
161

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:34     ` reinert
@ 2021-03-17 14:47       ` AdaMagica
  2021-03-17 15:37         ` Jeffrey R. Carter
  0 siblings, 1 reply; 16+ messages in thread
From: AdaMagica @ 2021-03-17 14:47 UTC (permalink / raw)


reinert schrieb am Mittwoch, 17. März 2021 um 15:34:13 UTC+1:
> onsdag 17. mars 2021 kl. 15:18:11 UTC+1 skrev AdaMagica: 
> > Create with mode Append 
> 
> "Mode => Append_File" only makes the files to "mix". 

??

Jeffrey:
RM A.10.2(2) For the procedures Create and Open: After a file with mode Out_File or Append_File is opened, the page length and line length are unbounded (both have the conventional value zero). After a file (of any mode) is opened, the current column, current line, and current page numbers are set to one. If the mode is Append_File, it is implementation defined whether a page terminator will separate preexisting text in the file from the new text to be written.

Doesn't sound like the contents are overwritten. The counting starts with 1, OK, but the old contents should be presevered for Append. Only the presence of a page terminator is implementation defined.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:17   ` reinert
  2021-03-17 14:21     ` reinert
  2021-03-17 14:34     ` Jeffrey R. Carter
@ 2021-03-17 15:01     ` Dmitry A. Kazakov
  2021-03-17 16:19     ` J-P. Rosen
  3 siblings, 0 replies; 16+ messages in thread
From: Dmitry A. Kazakov @ 2021-03-17 15:01 UTC (permalink / raw)


On 2021-03-17 15:17, reinert wrote:
> onsdag 17. mars 2021 kl. 13:49:23 UTC+1 skrev J-P. Rosen:
>> Le 17/03/2021 à 13:39, reinert a écrit :
> .......
>>>
>> Create always "creates" the file, i.e. if it exists, it is overwritten.
>> What would you expect?
> 
> Sorry to be imprecise. The files for two instances of the task have different names.
> For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten.
> When I run the two task separately (with various tasks between) then "name_1" is not overwritten.

Look how you pass the file name to the tasks. Normally there must be an 
entry point that *copies* the parameter during rendezvous to a 
task-local string and opens the file with the copy after leaving the 
rendezvous.

But if you come to an idea of using a global variable, an unbounded 
string or anything alike with *referential* semantics, you will get 
bitten, if that is updated concurrently.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 12:39 Attempting to create file i task reinert
  2021-03-17 12:49 ` J-P. Rosen
@ 2021-03-17 15:20 ` Shark8
  1 sibling, 0 replies; 16+ messages in thread
From: Shark8 @ 2021-03-17 15:20 UTC (permalink / raw)


On Wednesday, March 17, 2021 at 6:39:05 AM UTC-6, reinert wrote:
> Hello, 
> 
> Assume task A starts subsequentially two times sub-sequentially (but not overlapping in time). It creates and closes a file: 
> 
> define 
> my_file : File_Type; 
> begin 
> Create (File => my_file, Mode => Out_File, Name => my_file_name); 
> ..some statements... 
> Close(my_file); 
> end; 
> 
> I now have the strange experience that task A overwrites the file 
> created the first time? Any idea where to look for the error? 
> 
> reinert

What I would do in this situation:
(1) Make a function that opens the file, on the exception where it does not exist it creates the file.
(2) For my own convenience, I would likely wrap the file-type in a controlled object which would close the file on Finalize, and has a "Get_Stream" method.
(3) Combine #1 and #2 so that creating #2's type does #1.
(4) Given the above, adding some debugging information is rather trivial.
(5) Once things are debugged, you can delete the debugging-info and you still have a useful framework for handling files.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:47       ` AdaMagica
@ 2021-03-17 15:37         ` Jeffrey R. Carter
  2021-03-17 16:56           ` AdaMagica
  0 siblings, 1 reply; 16+ messages in thread
From: Jeffrey R. Carter @ 2021-03-17 15:37 UTC (permalink / raw)


On 3/17/21 3:47 PM, AdaMagica wrote:
> 
> RM A.10.2(2) For the procedures Create and Open: After a file with mode Out_File or Append_File is opened, the page length and line length are unbounded (both have the conventional value zero). After a file (of any mode) is opened, the current column, current line, and current page numbers are set to one. If the mode is Append_File, it is implementation defined whether a page terminator will separate preexisting text in the file from the new text to be written.
> 
> Doesn't sound like the contents are overwritten. The counting starts with 1, OK, but the old contents should be presevered for Append. Only the presence of a page terminator is implementation defined.

ARM A.8.2 says that Create "Establishes a new external file". A new file has no 
contents.

You might also want to look at this discussions here on c.l.a

https://groups.google.com/g/comp.lang.ada/c/2JYJeBtpm2g/m/H2TAaPlcBgAJ

where Randy Brukardt says that Create with Append_File is defined by the ARM to 
be the same as Out_File.

You might also want to experiment with various compilers and see what they do.

-- 
Jeff Carter
"In our experiments, the [Ada] compile[r] was able to find not
just typographical errors, but also conceptual errors in the
development of the code."
Scott and Bagheri
161

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 14:17   ` reinert
                       ` (2 preceding siblings ...)
  2021-03-17 15:01     ` Dmitry A. Kazakov
@ 2021-03-17 16:19     ` J-P. Rosen
  2021-03-17 16:56       ` reinert
  3 siblings, 1 reply; 16+ messages in thread
From: J-P. Rosen @ 2021-03-17 16:19 UTC (permalink / raw)


Le 17/03/2021 à 15:17, reinert a écrit :

> Sorry to be imprecise. The files for two instances of the task have different names.
> For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten.
> When I run the two task separately (with various tasks between) then "name_1" is not overwritten.
> 
The first thing I would do is to print the variable my_file_name to 
check if, due to an unrelated bug, they happen to be the same...


-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 15:37         ` Jeffrey R. Carter
@ 2021-03-17 16:56           ` AdaMagica
  0 siblings, 0 replies; 16+ messages in thread
From: AdaMagica @ 2021-03-17 16:56 UTC (permalink / raw)


Jeffrey R. Carter schrieb am Mittwoch, 17. März 2021 um 16:37:42 UTC+1:
> On 3/17/21 3:47 PM, AdaMagica wrote: 
> > 
> > RM A.10.2(2) For the procedures Create and Open: After a file with mode Out_File or Append_File is opened, the page length and line length are unbounded (both have the conventional value zero). After a file (of any mode) is opened, the current column, current line, and current page numbers are set to one. If the mode is Append_File, it is implementation defined whether a page terminator will separate preexisting text in the file from the new text to be written. 
> ARM A.8.2 says that Create "Establishes a new external file". A new file has no 
> contents.

Uh ah, I overlooked this in the above citation: After a file (of any mode) is *opened*, 
But the next sentence for Append does not make it clear whether this applies only to Open. It sounds like the old contents are saved for both, Open and Create.
So very bad wording here. But it makes sense that Create creates a new (hence empty) file.

> You might also want to look at this discussions here on c.l.a
> https://groups.google.com/g/comp.lang.ada/c/2JYJeBtpm2g/m/H2TAaPlcBgAJ
>where Randy Brukardt says that Create with Append_File is defined by the ARM to
>be the same as Out_File.

Thanx for the reminder of this discussion.
Christoph

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 16:19     ` J-P. Rosen
@ 2021-03-17 16:56       ` reinert
  2021-03-17 20:13         ` Simon Wright
  0 siblings, 1 reply; 16+ messages in thread
From: reinert @ 2021-03-17 16:56 UTC (permalink / raw)


Seems like I have a task synchronization problem. I tried to avoid "tasking" and it now works fine.

reinert

onsdag 17. mars 2021 kl. 17:19:15 UTC+1 skrev J-P. Rosen:
> Le 17/03/2021 à 15:17, reinert a écrit : 
> 
> > Sorry to be imprecise. The files for two instances of the task have different names. 
> > For example "name_1" and "name_2" respectively. My problem is that the (external) file "name_1" is overwritten. 
> > When I run the two task separately (with various tasks between) then "name_1" is not overwritten. 
> >
> The first thing I would do is to print the variable my_file_name to 
> check if, due to an unrelated bug, they happen to be the same...
> -- 
> J-P. Rosen 
> Adalog 
> 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX 
> Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 
> http://www.adalog.fr

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Attempting to create file i task
  2021-03-17 16:56       ` reinert
@ 2021-03-17 20:13         ` Simon Wright
  0 siblings, 0 replies; 16+ messages in thread
From: Simon Wright @ 2021-03-17 20:13 UTC (permalink / raw)


reinert <reinkor@gmail.com> writes:

> Seems like I have a task synchronization problem. I tried to avoid
> "tasking" and it now works fine.

Until whatever it was you did happens again/in your next program.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-03-17 20:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-17 12:39 Attempting to create file i task reinert
2021-03-17 12:49 ` J-P. Rosen
2021-03-17 14:17   ` reinert
2021-03-17 14:21     ` reinert
2021-03-17 14:34     ` Jeffrey R. Carter
2021-03-17 15:01     ` Dmitry A. Kazakov
2021-03-17 16:19     ` J-P. Rosen
2021-03-17 16:56       ` reinert
2021-03-17 20:13         ` Simon Wright
2021-03-17 14:18   ` AdaMagica
2021-03-17 14:33     ` Jeffrey R. Carter
2021-03-17 14:34     ` reinert
2021-03-17 14:47       ` AdaMagica
2021-03-17 15:37         ` Jeffrey R. Carter
2021-03-17 16:56           ` AdaMagica
2021-03-17 15:20 ` Shark8

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox