From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: About protected objects: entries with barriers depending on external data = bad practice ?
Date: Sun, 12 Nov 2017 11:02:09 +0100
Date: 2017-11-12T11:02:09+01:00 [thread overview]
Message-ID: <ou9671$rl4$1@dont-email.me> (raw)
In-Reply-To: <eba98c11-5a28-476d-b508-96e73469a256@googlegroups.com>
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
next prev parent reply other threads:[~2017-11-12 10:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2017-11-16 1:03 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox