comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Eachus <rieachus@comcast.net>
Subject: Re: Question on type invariants
Date: Thu, 26 Jan 2017 08:18:41 -0800 (PST)
Date: 2017-01-26T08:18:41-08:00	[thread overview]
Message-ID: <8706d548-a9d5-48e5-aa6f-fd33013a2fd1@googlegroups.com> (raw)
In-Reply-To: <65f79e53-a468-4b77-8ee1-440c26a09371@googlegroups.com>

On Wednesday, January 25, 2017 at 3:38:53 AM UTC-5, reinkor wrote:
 
> In principle I could mark A and S with a "last-modified-time-flag" so I can update S when I find it necessary. This has similarities to unix "make". Bad idea?

Responding to this point only, there are two decent ways to maintain last modified values for A and S.  One way is to store timestamps. Update_S then compares the values of last_modified for A and S for equality.  If not equal, copy the timestamp from A to S, and do the update work, otherwise exit immediately.  The potential problem here is that the timestamps may not be of sufficient granularity.  The other approach is to use a counter, updated every time A is.  Again comparing for equality can be used to avoid the excess work.  In this case you need to worry about whether your counter is large enough.  My tendency would be just to use a 64-bit integer.  But you may not have atomic updates for 64-bit values, and S and A may be maintained by different tasks.

For this case, there is a neat trick.  Use a smaller integer type for the counter.  When the S counter value is smaller than the A counter value, set both counters to zero, and do the S update.  This can all be done with a protected object, but with careful coding, it can be done with the counters being marked atomic.  Notice that it is possible that an update to A can occur while processing S.  You may need to use protected objects to insure that S_Update sees a consistent view of A.  However, it doesn't really matter whether the update to A is reflected in the new S, you may just have an additional, unneeded update of S now or later.

  parent reply	other threads:[~2017-01-26 16:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25  8:38 Question on type invariants reinkor
2017-01-25 22:06 ` Randy Brukardt
2017-01-26  4:31   ` reinkor
2017-01-26  4:32   ` reinkor
2017-01-26  8:38 ` Dmitry A. Kazakov
2017-01-27  9:20   ` reinkor
2017-01-27  9:47     ` Dmitry A. Kazakov
2017-01-31  6:44       ` reinkor
2017-01-26 16:18 ` Robert Eachus [this message]
2017-01-27  5:35   ` reinkor
2017-01-27  5:47   ` reinkor
replies disabled

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