comp.lang.ada
 help / color / mirror / Atom feed
* time of update of new values for out mode parameters
@ 2018-03-19 12:21 Mehdi Saada
  2018-03-19 13:10 ` Simon Clubley
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Mehdi Saada @ 2018-03-19 12:21 UTC (permalink / raw)


Hi.

When are new values of out or in out mode parameters written in the actual variable ? Is it instantaneous as I presume it is with access mode parameters, or is it done at the end of the function/procedure/accept statement ?

Mehdi

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

* Re: time of update of new values for out mode parameters
  2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
@ 2018-03-19 13:10 ` Simon Clubley
  2018-03-19 15:01 ` AdaMagica
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Simon Clubley @ 2018-03-19 13:10 UTC (permalink / raw)


On 2018-03-19, Mehdi Saada <00120260a@gmail.com> wrote:
> Hi.
>
> When are new values of out or in out mode parameters written in the actual
> variable ? Is it instantaneous as I presume it is with access mode parameters,
> or is it done at the end of the function/procedure/accept statement ?
>

It depends on when the compiler's generated code gets around to it.

While that sounds flippant, it isn't and reflects the nature of writing
code which is compiled by an optimising compiler.

If this matters to you, have a look at the Volatile and Atomic pragmas.

https://en.wikibooks.org/wiki/Ada_Programming/Pragmas/Volatile
https://en.wikibooks.org/wiki/Ada_Programming/Pragmas/Atomic

What is the underlying issue or problem you are trying to solve ?

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world

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

* Re: time of update of new values for out mode parameters
  2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
  2018-03-19 13:10 ` Simon Clubley
@ 2018-03-19 15:01 ` AdaMagica
  2018-03-19 16:11 ` Mehdi Saada
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: AdaMagica @ 2018-03-19 15:01 UTC (permalink / raw)


Am Montag, 19. März 2018 13:21:08 UTC+1 schrieb Mehdi Saada:
> Hi.
> 
> When are new values of out or in out mode parameters written in the actual variable ? Is it instantaneous as I presume it is with access mode parameters, or is it done at the end of the function/procedure/accept statement ?
> 
> Mehdi

I see that you post a lot of questions which are easily answered ba y look in the RM. Please try to read it - you will get accustomed to its style.

To this actual question:

Ada doe not generally define how parameters are transferred. This is often left to the compiler who will do the correct choice.

Always transferred by copy (in, in out, out): scalar objects.
Always transferred by reference: tagged types, limited types.

Copy in: when the subprogram is called.
Copy out: when the subprogram is left correctly (not when left via an exception).


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

* Re: time of update of new values for out mode parameters
  2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
  2018-03-19 13:10 ` Simon Clubley
  2018-03-19 15:01 ` AdaMagica
@ 2018-03-19 16:11 ` Mehdi Saada
  2018-03-19 17:09   ` AdaMagica
  2018-03-19 22:42 ` Randy Brukardt
  2018-03-20  2:33 ` Mehdi Saada
  4 siblings, 1 reply; 9+ messages in thread
From: Mehdi Saada @ 2018-03-19 16:11 UTC (permalink / raw)


It might sound strange to you, but there's no underlying issue... I'm just curious. I know it seems stupid to annoy oneself (and others) with things I won't be in need to know until any reasonable time, but I do that all the time, and I learn a lot like this.
It seems to me harder to find the correct section for the problem, than actually reading it. I'll try harder. It's just a pain, that sometimes questions easily formulated, are not that easily answered/searched for...


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

* Re: time of update of new values for out mode parameters
  2018-03-19 16:11 ` Mehdi Saada
@ 2018-03-19 17:09   ` AdaMagica
  0 siblings, 0 replies; 9+ messages in thread
From: AdaMagica @ 2018-03-19 17:09 UTC (permalink / raw)


Am Montag, 19. März 2018 17:11:42 UTC+1 schrieb Mehdi Saada:
> It might sound strange to you, but there's no underlying issue... I'm just curious. I know it seems stupid to annoy oneself (and others) with things I won't be in need to know until any reasonable time, but I do that all the time, and I learn a lot like this.
> It seems to me harder to find the correct section for the problem, than actually reading it. I'll try harder. It's just a pain, that sometimes questions easily formulated, are not that easily answered/searched for...

The corresponding chapters are 6.2 Formal Parameter Modes and 6.4.1 Parameter Associations. They are not a hard read.

It's OK to ask here if you don't understand (well) the RM. But reading these chapters answer further questions you might have.

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

* Re: time of update of new values for out mode parameters
  2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
                   ` (2 preceding siblings ...)
  2018-03-19 16:11 ` Mehdi Saada
@ 2018-03-19 22:42 ` Randy Brukardt
  2018-03-20  2:33 ` Mehdi Saada
  4 siblings, 0 replies; 9+ messages in thread
From: Randy Brukardt @ 2018-03-19 22:42 UTC (permalink / raw)


"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:4598be4c-7a4b-4bdd-8fd3-99b943e77823@googlegroups.com...
> Hi.
>
> When are new values of out or in out mode parameters written in the actual
> variable ? Is it instantaneous as I presume it is with access mode 
> parameters,
> or is it done at the end of the function/procedure/accept statement ?

It depends. In well-written code, it shouldn't matter (aliasing being a 
major cause of problems, so one should only use a single access path in any 
single subprogram).

                   Randy.




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

* Re: time of update of new values for out mode parameters
  2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
                   ` (3 preceding siblings ...)
  2018-03-19 22:42 ` Randy Brukardt
@ 2018-03-20  2:33 ` Mehdi Saada
  2018-03-20  5:54   ` Simon Wright
  4 siblings, 1 reply; 9+ messages in thread
From: Mehdi Saada @ 2018-03-20  2:33 UTC (permalink / raw)


Ok. To be honest, the use case I had in mind was a wrong one, is meant to be implemented through protected types.

let's say:
procedure FOO (A: out A_TYPE) is
... A := something; -- Can't know when it's copied back
procedure FOO2 (a: access A_TYPE) is
... A.all := something; -- Can't know for sure either, right ?
but I am sure with
until some_absolute_time; some_protected_object.Write(something);
, and another task can use it safely.
Now, about procedure FOO (A: out A_TYPE) is
... delay until some_absolute_time;
A := something; delay until the_other_hour;
I shall assume that inside FOO, A = something" (obviously), but shall not assume this for the world outside FOO ? 

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

* Re: time of update of new values for out mode parameters
  2018-03-20  2:33 ` Mehdi Saada
@ 2018-03-20  5:54   ` Simon Wright
  2018-03-20 11:18     ` Mehdi Saada
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Wright @ 2018-03-20  5:54 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:

> Ok. To be honest, the use case I had in mind was a wrong one, is meant
> to be implemented through protected types.
>
> let's say:
> procedure FOO (A: out A_TYPE) is
> ... A := something; -- Can't know when it's copied back
> procedure FOO2 (a: access A_TYPE) is
> ... A.all := something; -- Can't know for sure either, right ?

All you can say is that it will have been copied out by the time you've
returned from the calls. But that must be enough; if there were two
threads making the different calls, how would you be able to tell which
made the earlier call?

> but I am sure with
> until some_absolute_time; some_protected_object.Write(something);
> , and another task can use it safely.
> Now, about procedure FOO (A: out A_TYPE) is
> ... delay until some_absolute_time;
> A := something; delay until the_other_hour;

You are seriously overthinking this.

> I shall assume that inside FOO, A = something" (obviously), but shall
> not assume this for the world outside FOO ?

At the level of Ada code, you have to assume this. How could you
possibly write any sort of reliable program if it were otherwise>? 


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

* Re: time of update of new values for out mode parameters
  2018-03-20  5:54   ` Simon Wright
@ 2018-03-20 11:18     ` Mehdi Saada
  0 siblings, 0 replies; 9+ messages in thread
From: Mehdi Saada @ 2018-03-20 11:18 UTC (permalink / raw)


Sorry, indeed it was pointless. In many occasions already I saw that logical and intuitive behaviors are (almost) always to be expected, I should trust Ada more by now.

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

end of thread, other threads:[~2018-03-20 11:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-19 12:21 time of update of new values for out mode parameters Mehdi Saada
2018-03-19 13:10 ` Simon Clubley
2018-03-19 15:01 ` AdaMagica
2018-03-19 16:11 ` Mehdi Saada
2018-03-19 17:09   ` AdaMagica
2018-03-19 22:42 ` Randy Brukardt
2018-03-20  2:33 ` Mehdi Saada
2018-03-20  5:54   ` Simon Wright
2018-03-20 11:18     ` Mehdi Saada

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