comp.lang.ada
 help / color / mirror / Atom feed
* Re: new_line in a put_line
@ 2002-12-03 11:52 Grein, Christoph
  2002-12-04  9:39 ` Fraser Wilson
  0 siblings, 1 reply; 30+ messages in thread
From: Grein, Christoph @ 2002-12-03 11:52 UTC (permalink / raw)


> I've seen a couple of mentions of problems using protected objects for
> atomic file output.  What's the specific issue?  I.e., why isn't this
> sufficient?
> 
>    protected File_Operation is
>       procedure Put_Line (Text : String);
>    end File_Operation;
> 
>    protected body File_Operation is
>       procedure Put_Line (Text : String) is
>       begin
>          Ada.Text_IO.Put_Line (Text);
>       end Put_Line;
>    end File_Operation;
> 
> Oh, wait on, is it something to do with 9.5.1(8)?

You've spotted it. Also 9.5.1(18).

> Fraser.



^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: new_line in a put_line
@ 2002-12-05  6:28 Grein, Christoph
  2002-12-05 14:19 ` Stephen Leake
  0 siblings, 1 reply; 30+ messages in thread
From: Grein, Christoph @ 2002-12-05  6:28 UTC (permalink / raw)


> > >>    procedure Put_Line (Text : String) is
> > >>       Get_It : Lock (Write_Mutex'Access);
> > >>    begin
> > >>       Ada.Text_IO.Put_Line (Text);
> > >>    end Put_Line;
> > >
> > >Something inside me rebels at using side-effects from a declaration
> > >like that. 
> > 
> > Right, right. It is also my opinion [there was a thread regarding this
> > subject in c.l.a] that using unused (:-)) objects probably indicates a
> > design problem. 
> 
> That's what pragma Unreferenced (in GNAT) is for; it documents that
> the object is declared only for the hidden effects of Initialize and
> Finalize.
> 
> Assuming Lock is a controlled type, that releases the lock in
> Finalize, this is an excellent design.

This should only be necessary for objects of not limited controlled types. As I said, 
limited controlled objects must not be optimized away.



^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: new_line in a put_line
@ 2002-12-05  6:16 Grein, Christoph
  2002-12-05  9:44 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 30+ messages in thread
From: Grein, Christoph @ 2002-12-05  6:16 UTC (permalink / raw)


> You might also pack seizing the mutex into a "proxy" object
> (File_Channel):
> 
>    type File_Channel is limited private;
>    procedure Put (File : in out File_Channel; Text : String);
>    procedure Put_Line (File : in out File_Channel; Text : String);
>    procedure New_Line (File : in out File_Channel; Text : String);
> ...
> private
>    type File_Channel is
>       new Ada.Finalization.Limited_Controlled with null record;
>    procedure Initialize (File : in out File_Channel);
>    procedure Finalize (File : in out File_Channel);
> 
> Initialize would seize the mutex, Finalize would release it. Thus only
> one instance of File_Channel may exist at a time.

No, nothing prevents you from declaring lots of File_Channel objects concurrently, even 
arrays of them.



^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: new_line in a put_line
@ 2002-12-04 10:03 Grein, Christoph
  0 siblings, 0 replies; 30+ messages in thread
From: Grein, Christoph @ 2002-12-04 10:03 UTC (permalink / raw)


> >    procedure Put_Line (Text : String) is
> >       Get_It : Lock (Write_Mutex'Access);
> >    begin
> >       Ada.Text_IO.Put_Line (Text);
> >    end Put_Line;
> 
> Something inside me rebels at using side-effects from a declaration
> like that.  I can't really talk; my database library unlocks objects
> as they go out of scope, but ... well, I know that code gets executed
> in declarations, but I don't necessarily want to be this aware of it.
> 
> On the other hand, it's just a monitor, I shouldn't be so scared :)

This is exactly the kind of use limited controlled types are destined for.
There is a paragraph in the AARM stating that such a (seemingly unused) object 
(Get_It) must not be optimized away.

For unlimited controlled types, this does not hold, i.e. they may be optimized 
away.



^ permalink raw reply	[flat|nested] 30+ messages in thread
* new_line in a put_line
@ 2002-12-02  5:36 Vlad
  2002-12-02  9:47 ` Preben Randhol
                   ` (3 more replies)
  0 siblings, 4 replies; 30+ messages in thread
From: Vlad @ 2002-12-02  5:36 UTC (permalink / raw)


Hi all,

Is there a way of prepending a new_line to a put_line.
The reason I need this is that I have multiple tasks outputing to a\
single file. Some of them use Text_IO.Put rather then Text_IO.Put_Line.
And because of this, some of these outputs get written on the same line
as my outputs.

TIA

--
Vladimir Bednikov






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

end of thread, other threads:[~2002-12-05 22:40 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-03 11:52 new_line in a put_line Grein, Christoph
2002-12-04  9:39 ` Fraser Wilson
  -- strict thread matches above, loose matches on Subject: below --
2002-12-05  6:28 Grein, Christoph
2002-12-05 14:19 ` Stephen Leake
2002-12-05  6:16 Grein, Christoph
2002-12-05  9:44 ` Dmitry A. Kazakov
2002-12-04 10:03 Grein, Christoph
2002-12-02  5:36 Vlad
2002-12-02  9:47 ` Preben Randhol
2002-12-02 17:04   ` Frank J. Lhota
2002-12-05 11:10     ` Preben Randhol
2002-12-02 10:14 ` Dmitry A. Kazakov
2002-12-02 14:57 ` Matthew Heaney
2002-12-03 11:33   ` Fraser Wilson
2002-12-03 15:01     ` Dmitry A. Kazakov
2002-12-04  9:31       ` Fraser Wilson
2002-12-04 14:10         ` Dmitry A. Kazakov
2002-12-04 15:23           ` Robert A Duff
2002-12-04 16:15             ` Dmitry A. Kazakov
2002-12-04 18:11               ` tmoran
2002-12-04 20:21                 ` Simon Wright
2002-12-05  9:36                 ` Dmitry A. Kazakov
2002-12-05 22:40                   ` tmoran
2002-12-04 15:25           ` Stephen Leake
2002-12-04 16:55             ` Jeffrey Carter
2002-12-04 17:24               ` Stephen Leake
2002-12-04 17:43               ` Warren W. Gay VE3WWG
2002-12-05  1:31                 ` Jeffrey Carter
2002-12-05 18:11                   ` Warren W. Gay VE3WWG
2002-12-02 15:49 ` Robert A Duff

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