comp.lang.ada
 help / color / mirror / Atom feed
* About protected objects: entries with barriers depending on external data = bad practice ?
@ 2017-11-12  5:23 reinert
  2017-11-12  7:32 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: reinert @ 2017-11-12  5:23 UTC (permalink / raw)


Mostly for curiosity:

Assume a protected entry with a barrier depending on external data - and it is waiting for its barrier to become true. It must be laborious to check the barrier depending on something "far-far away"? How is this checking done in practice? The entry waits for other entries, procedures or functions and when they arrive, it may start before them? Or something more efficient?

Letting barriers depend on external data = asking for trouble?

reinert,
https://korsnesbiocomputing.no/


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

* Re: About protected objects: entries with barriers depending on external data = bad practice ?
  2017-11-12  5:23 About protected objects: entries with barriers depending on external data = bad practice ? reinert
@ 2017-11-12  7:32 ` Dmitry A. Kazakov
  2017-11-12  8:15   ` Simon Wright
  2017-11-12 10:02 ` Jeffrey R. Carter
  2017-11-16  1:03 ` Randy Brukardt
  2 siblings, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2017-11-12  7:32 UTC (permalink / raw)


On 2017-11-12 06:23, reinert wrote:

> Assume a protected entry with a barrier depending on external data -
> and it is waiting for its barrier to become true. It must be 
> laborious to check the barrier depending on something "far-far away"?
> How is this checking done in practice? The entry waits for other
> entries, procedures or functions and when they arrive, it may start
> before them? Or  something more efficient?

Barrier is evaluated only when required to. E.g. in the case of a 
protected object after you leave an object's procedure or entry. Updates 
from outside are most likely ignored.

> Letting barriers depend on external data = asking for trouble?

Well, most of the time.

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

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

* Re: About protected objects: entries with barriers depending on external data = bad practice ?
  2017-11-12  7:32 ` Dmitry A. Kazakov
@ 2017-11-12  8:15   ` Simon Wright
  0 siblings, 0 replies; 5+ messages in thread
From: Simon Wright @ 2017-11-12  8:15 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2017-11-12 06:23, reinert wrote:
>
>> Assume a protected entry with a barrier depending on external data -
>> and it is waiting for its barrier to become true. It must be
>> laborious to check the barrier depending on something "far-far away"?
>> How is this checking done in practice? The entry waits for other
>> entries, procedures or functions and when they arrive, it may start
>> before them? Or something more efficient?
>
> Barrier is evaluated only when required to. E.g. in the case of a
> protected object after you leave an object's procedure or
> entry. Updates from outside are most likely ignored.

GNAT generates a barrier-evaluation function which is called as Dmitry
says. If that function (i.e. the entry condition) involves external data
then the external data will be considered, but only at that time.

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

* Re: About protected objects: entries with barriers depending on external data = bad practice ?
  2017-11-12  5:23 About protected objects: entries with barriers depending on external data = bad practice ? reinert
  2017-11-12  7:32 ` Dmitry A. Kazakov
@ 2017-11-12 10:02 ` Jeffrey R. Carter
  2017-11-16  1:03 ` Randy Brukardt
  2 siblings, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2017-11-12 10:02 UTC (permalink / raw)


On 11/12/2017 06:23 AM, reinert wrote:
> 
> Assume a protected entry with a barrier depending on external data - and it is waiting for its barrier to become true. It must be laborious to check the barrier depending on something "far-far away"? How is this checking done in practice? The entry waits for other entries, procedures or functions and when they arrive, it may start before them? Or something more efficient?
> 
> Letting barriers depend on external data = asking for trouble?

Barriers are evaluated when the PO's state changes; that is, as others have 
said, when a procedure or entry of the same PO has executed. So having a barrier 
that depends on external data requires some way of notifying the PO that the 
external data have changed. Typically this involves polling:

External : Boolean := False;
pragma Atomic (External); -- or Volatile

protected PO is
    procedure Evaluate_Barrier; -- Causes Wait's barrier to be evaluated
    entry Wait; -- Blocks caller until External becomes True
end PO;

protected body PO is
    procedure Evaluate_Barrier is null;

    entry Wait when External is
       -- Nothing to see here, folks
    begin -- Wait
       External := False;
    end Wait;
end PO;

task Poller;

task body Poller is
    Interval : constant Ada.Real_Time.Time_Span := ...;

    Next : Ada.Real_Time.Time := Ada.Real_Time.Clock + Interval;
begin -- Poller
    Forever : loop
       delay until Next;

       Next := Next + Interval;
       PO.Evaluate_Barrier;
    end loop Forever;
end Poller;

Of course, there are lots of opportunities for error here, so it should be 
avoided if possible.

-- 
Jeff Carter
"Ah, go away or I'll kill ya."
Never Give a Sucker an Even Break
100


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

* Re: About protected objects: entries with barriers depending on external data = bad practice ?
  2017-11-12  5:23 About protected objects: entries with barriers depending on external data = bad practice ? reinert
  2017-11-12  7:32 ` Dmitry A. Kazakov
  2017-11-12 10:02 ` Jeffrey R. Carter
@ 2017-11-16  1:03 ` Randy Brukardt
  2 siblings, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2017-11-16  1:03 UTC (permalink / raw)


"reinert" <reinkor@gmail.com> wrote in message 
news:eba98c11-5a28-476d-b508-96e73469a256@googlegroups.com...
>Letting barriers depend on external data = asking for trouble?

Yes. Barriers are only checked after some other protected action completes 
(that might change the *internal* data). There is no attempt to check for 
changes in external data.

                       Randy. 



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

end of thread, other threads:[~2017-11-16  1:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-12  5:23 About protected objects: entries with barriers depending on external data = bad practice ? reinert
2017-11-12  7:32 ` Dmitry A. Kazakov
2017-11-12  8:15   ` Simon Wright
2017-11-12 10:02 ` Jeffrey R. Carter
2017-11-16  1:03 ` Randy Brukardt

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