Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is a Boolean type inherently atomic ?

52 views
Skip to first unread message

Rod Kay

unread,
May 12, 2023, 8:17:40 AM5/12/23
to
Surely only the least significant bit of the least significant byte
is relevant and so the value cannot be garbled by one task writing and
another reading at the same time ?


Regards.

Jeffrey R.Carter

unread,
May 12, 2023, 8:55:10 AM5/12/23
to
Boolean types with other representations using multiple bits are possible, so
your assumption doesn't hold.

--
Jeff Carter
"Many times we're given rhymes that are quite unsingable."
Monty Python and the Holy Grail
57

J-P. Rosen

unread,
May 12, 2023, 12:58:06 PM5/12/23
to
Le 12/05/2023 à 14:53, Jeffrey R.Carter a écrit :
> On 2023-05-12 14:17, Rod Kay wrote:
>>     Surely only the least significant bit of the least significant
>> byte is relevant and so the value cannot be garbled by one task
>> writing and another reading at the same time ?
>
> Boolean types with other representations using multiple bits are
> possible, so your assumption doesn't hold.
>
True, especially considering the special exception for boolean types in
13.4(8)

Anyway, if you intend to access a variable from multiple tasks, it
doesn't cost much to add an aspect Atomic to the declaration, at least
to inform the reader!

--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
https://www.adalog.fr https://www.adacontrol.fr

Niklas Holsti

unread,
May 12, 2023, 1:40:00 PM5/12/23
to
That seems very likely indeed, unless (as others have commented) the
representation has been specified to use more bits. However, the Ada RM
states in C.6(8/3) that "every atomic type or object is also defined to
be volatile", and of course Boolean variables are not considered
volatile unless they are specified to be Atomic or Volatile. So a
Boolean type is not inherently atomic in the Ada RM sense of "atomic".

And of course if you use a shared variable to communicate data between
tasks, that variable should be marked as Volatile, and there should also
be some Atomic accesses to ensure that actions are "sequential", so
marking the variable as Atomic is best.

AdaMagica

unread,
May 12, 2023, 2:02:17 PM5/12/23
to
AARM 3.5.3(1.a), 13.4(8.b, 10/5) has some information about boolean representations.

Rod Kay

unread,
May 12, 2023, 8:29:30 PM5/12/23
to
Okay, thank you all for the information.


Regards.
0 new messages