comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: Pragma Atomic
Date: Wed, 10 Jan 2001 04:27:37 GMT
Date: 2001-01-10T04:27:37+00:00	[thread overview]
Message-ID: <93gobj$u0c$1@nnrp1.deja.com> (raw)
In-Reply-To: 93g48c$ehk$1@nnrp1.deja.com

In article <93g48c$ehk$1@nnrp1.deja.com>,
  Adam Beneschan <adam@irvine.com> wrote:
> It wouldn't make sense to declare a scalar object, whose size
> is a natural size on the processor, to be Atomic, since the
> processor's reads and writes of
> such an object would automatically be indivisible anyway.

AARGH! It is this kind of thinking that leads to casually
non-portable code. Just think about what you are saying, you
are saying that if you write

   type x is mod 2 ** 64;
   v : x;

and you know that you are operating on a 64-bit machine where
64-bit reads and writes are indivisible, and further more you
happen to know that the compiler uses these instructions for
reading and writing v, then you need not delare v Atomic
because it is not needed!

The whole point of Atomic is to *check* that your assumption
that reads and writes are atomic is correct. It is not unusual
in an Ada compiler for pragma Atomic to have no effect on the
code that pragma Volatile would not have. THe difference is
that you are asking the compiler to check that on the target
you are using, you will indeed get Atomic access.

So please declare v Atomic in the code above. It will have no
effect on your 64-bit machine, but it will cause your code to
be considered illegal when you port it to a 32-bit machine that
does not support your expectations.

> Atomic replaces Ada 83's pragma Shared. The name 'Shared' was
> confusing, because the pragma was not used to mark variables
> as shared."  I'm not sure how the previous Shared pragma had
> anything to do with indivisiblity or atomicity,

Pleaes read the Ada 83 RM which makes this quite clear.

> however, so I don't see how Atomic
> replaces it.

Because pragma Atomic in Ada 95 means EXACTLY the same
think as pragma Shared in Ada 83. The name change was to
avoid the confusing name (which certainly confused you :-)


Sent via Deja.com
http://www.deja.com/



  parent reply	other threads:[~2001-01-10  4:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-09 22:44 Pragma Atomic Adam Beneschan
2001-01-09 23:16 ` mark.biggar
2001-01-10  4:27 ` Robert Dewar [this message]
2001-01-10 17:53 ` Nick Roberts
2001-01-11 14:00   ` Tucker Taft
2001-01-11 15:06     ` Nick Roberts
replies disabled

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