Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Jacob Spar » Sat, 30 Apr 2005 21:45:53



I thought entries of protected objects also were "protected actions".
Unfortunately RM 9.5.1 isn't so clear on that question, that I am sure
if that is actually the case or not.

If entries on protected objects are not "protected actions", then that
is definitely a sensible solution.

I think I need an explanation of the difference between entries and
procedures of protected objects. Any suggestion of some reading
materials?

Jacob
--
SA fights for the right of the individual.? es. Those of the individual George W. Bush.? -- with thanks to Olfax
 
 
 


Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Egil H. Hi » Sat, 30 Apr 2005 23:26:06


RM 9.5.1(18):
Certain language-defined subprograms are potentially blocking. In
particular, the subprograms of the language-defined input-output
packages that manipulate files (implicitly or explicitly) are potentially
blocking.



RM 9.5.3(8):
... For a call on an entry of a protected object, a new protected action
is started on the object (see 9.5.1).


~egilhh
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Bjn Lundi » Sun, 01 May 2005 00:23:11


2005-04-29 kl. 14.45 skrev Jacob Sparre Andersen:





Ada As A Second Language by Norman Cohen

< http://www.yqcomputer.com/
-4955053?v=glance>
Has a nice and long chapter about protected objects and tasking

As a remark to the issue of text_io being potentially blocking, I've
developed code
that works as it should with Windows and gnat, but came to a total
freeze of the process
when compiled with Object Ada. The freeze occured when calling text_io
inside a protected procedure.
Replacing the protected object with another task solved it.

In the book above, the author mentions that io inside protected objects
will either freeze the process,
or work, but with the protection disabled, or work very well? Anyway, I
will always be carefull with
protected objects in the future.

/Bjn
Bjn Lundin
bnl at spray dot se



2005-04-29 kl. 14.45 skrev Jacob Sparre Andersen:






</excerpt>

<excerpt><excerpt>If calls to Ada.Text_IO _are_ potentially blocking
operations,

that means that one has to move the calls to a task.

</excerpt>

and what about putting them into an entry of a protected object?

</excerpt>

</excerpt>


<excerpt>I think I need an explanation of the difference between
entries and

procedures of protected objects. Any suggestion of some reading

materials?


</excerpt><fontfamily><param>Arial</param><x-tad-bigger>
</x-tad-bigger><bold><x-tad-bigger>Ada</x-tad-bigger></bold><x-tad-bigger>
As A
</x-tad-bigger><bold><x-tad-bigger>Second</x-tad-bigger></bold><x-tad-bigger> </x-tad-bigger><bold><x-tad-bigger>Language</x-tad-bigger></bold><x-tad-bigger>
by Norman Cohen


<< http://www.yqcomputer.com/ ;

Has a nice and long chapter about protected objects and tasking


</x-tad-bigger></fontfamily>As a remark to the issue of text_io being
potentially blocking, I've developed code

that works as it should with Windows and gnat, but came to a total
freeze of the process

when compiled with Object Ada. The freeze occured when calling text_io
inside a protected procedure.

Replacing the protected object with another task solved it.


In the book above, the author mentions that io inside protected
objects will either freeze the process,

or work, but with the protection disabled, or work very well? Anyway,
I will always be carefull with

protected objects in the future.


/Bjn

Bjn Lundin

bnl at spray dot se
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Jacob Spar » Sun, 01 May 2005 05:28:45


That was the paragraph I was looking for. Unfortunately it wasn't in
the index under "potentially blocking operation". Now it is (in my
printed version).


It was exactly that sentence I was of about the meaning of. I guess
your interpretation of it is that entries of protected objects, like
their functions and procedures, are protected actions.

Thanks.

Jacob
--
recursive, adj.; see recursive
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Randy Bruk » Sun, 01 May 2005 05:39:26

"Egil H. Hik" < XXXX@XXXXX.COM > wrote in






Right. We had a big fight about this rule in the ARG (some people wanting to
repeal or modify it), but ultimately it was left to stand. So it isn't
portable to call Text_IO from a protected object; it might raise
Program_Error or deadlock.

I think it actually does work in Janus/Ada and in GNAT, but (in our case at
least), we aren't making any promises that that will remain the case. And
its always bad practice to write code that will work only on a few
compilers, especially something as hard to track down as this would be.

Randy.
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Lionel Dra » Sun, 01 May 2005 06:23:30

Randy Brukardt a rit :
...

I fully agree with you, Randy, but it's quite difficult to ensure that
no compiler dependant behavior is used in the code, because no compiler
I am aware of is kind enough to put a warning on all compiler/platform
dependencies.

When porting, some problems will be caught at compilation time (for
example representation clause that do not compile with another compiler).
Some will be caught early at run time (for example elaboration order issue).
But some, like this one, may not be noticed before delivery, and will be
really difficult to track down, as you said.

And here is the limit of Ada portability Myth.
OK, Ada is probably the most portable industrial compiled language.
OK, porting an Ada code is much faster than any other compiled language.
But the situation is not perfect. Ada is just 99.5% portable :-)

Those "inaccuracy" in the Ada semantics are possibly inevitable,
precisely because of portability accross platform, and maybe also to
preserve different compiler implementation options.

So, the only way I see to ensure that an general Ada code is fully
portable is an ASIS tools that will warn about all risky code.
A kind of portability lint.

What dou you think about it?

--
Lionel Draghi
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by fabio de f » Sun, 01 May 2005 06:57:21


potentially
actions".
sure
action

Thank you all for every insight on the subject. Anyway I don't yet
understand whether you mean that potentially "blocking" subprograms
should be put in a protected object or inversely they shouldn't.

In this thread I've been suggested to put the IO in a protected object.
Is it needed to do so?

What do you mean by "blocking"? I suppose you mean that OS can put that
process in a wait queue and switch to a new one, may be because the
first is waiting for some event like device IO. Is it correct?

Ciao,

fabio de francesco
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by fabio de f » Sun, 01 May 2005 07:11:52


that
compiler
compiler/platform

Isn't there in GCC/GNAT any options like "-pedantic" and "-ansi" in
order to reject all programs that do not strictly follow the standard?

fabio
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Jeffrey Ca » Sun, 01 May 2005 12:45:12


For GNAT,

-gnato -fstack-check -gnatE

make it strictly follow the standard. That won't affect what happens in
your problem.

Blocking operations in protected operations are a bounded error. That
means don't do it.

Doing IO to the same file from multiple tasks may cause interleaving.

So the simple solution to your problem as given is to define a subtype
of String

subtype Task_Name is String (1 .. 6);

to use in your entry and Msg object, and have another task to do the
output. That should solve your deadlock and be portable.

If task names need to be different lengths, then Msg could be an
[Un]Bounded_String.

--
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Lionel Dra » Sun, 01 May 2005 16:21:08

fabio de francesco a rit :
...

But non portable programs follows the standard, that's my point.
(Fortunatly, in the Ada world, not following the standard is not an option).

That's why you may write code that perfectly run with GNAT, unaware that
it won't run that fine with another one.

--
Lionel
 
 
 

Ada.Text_IO and protected objects (Was: [newbie question] tasks and protected types)

Post by Jean-Pierr » Tue, 03 May 2005 17:11:29

Lionel Draghi a rit :
[snip discussion about potentially blocking operations]
That could be a job for AdaControl, I've put it on my list of to-do rules.

Of course, if someone is *really* interested and has some funding
available, it will raise its priority :-)

--
---------------------------------------------------------
J-P. Rosen ( XXXX@XXXXX.COM )
Visit Adalog's web site at http://www.yqcomputer.com/