comp.lang.ada
 help / color / mirror / Atom feed
* Is a Boolean type inherently atomic ?
@ 2023-05-12 12:17 Rod Kay
  2023-05-12 12:53 ` Jeffrey R.Carter
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Rod Kay @ 2023-05-12 12:17 UTC (permalink / raw)


    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.

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

* Re: Is a Boolean type inherently atomic ?
  2023-05-12 12:17 Is a Boolean type inherently atomic ? Rod Kay
@ 2023-05-12 12:53 ` Jeffrey R.Carter
  2023-05-12 16:56   ` J-P. Rosen
  2023-05-12 17:38 ` Niklas Holsti
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R.Carter @ 2023-05-12 12:53 UTC (permalink / raw)


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.

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

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

* Re: Is a Boolean type inherently atomic ?
  2023-05-12 12:53 ` Jeffrey R.Carter
@ 2023-05-12 16:56   ` J-P. Rosen
  0 siblings, 0 replies; 6+ messages in thread
From: J-P. Rosen @ 2023-05-12 16:56 UTC (permalink / raw)


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

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

* Re: Is a Boolean type inherently atomic ?
  2023-05-12 12:17 Is a Boolean type inherently atomic ? Rod Kay
  2023-05-12 12:53 ` Jeffrey R.Carter
@ 2023-05-12 17:38 ` Niklas Holsti
  2023-05-12 18:02 ` AdaMagica
  2023-05-13  0:28 ` Rod Kay
  3 siblings, 0 replies; 6+ messages in thread
From: Niklas Holsti @ 2023-05-12 17:38 UTC (permalink / raw)


On 2023-05-12 15: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 ?


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.

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

* Re: Is a Boolean type inherently atomic ?
  2023-05-12 12:17 Is a Boolean type inherently atomic ? Rod Kay
  2023-05-12 12:53 ` Jeffrey R.Carter
  2023-05-12 17:38 ` Niklas Holsti
@ 2023-05-12 18:02 ` AdaMagica
  2023-05-13  0:28 ` Rod Kay
  3 siblings, 0 replies; 6+ messages in thread
From: AdaMagica @ 2023-05-12 18:02 UTC (permalink / raw)


AARM 3.5.3(1.a), 13.4(8.b, 10/5) has some information about boolean representations.

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

* Re: Is a Boolean type inherently atomic ?
  2023-05-12 12:17 Is a Boolean type inherently atomic ? Rod Kay
                   ` (2 preceding siblings ...)
  2023-05-12 18:02 ` AdaMagica
@ 2023-05-13  0:28 ` Rod Kay
  3 siblings, 0 replies; 6+ messages in thread
From: Rod Kay @ 2023-05-13  0:28 UTC (permalink / raw)


    Okay, thank you all for the information.


Regards.

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

end of thread, other threads:[~2023-05-13  0:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12 12:17 Is a Boolean type inherently atomic ? Rod Kay
2023-05-12 12:53 ` Jeffrey R.Carter
2023-05-12 16:56   ` J-P. Rosen
2023-05-12 17:38 ` Niklas Holsti
2023-05-12 18:02 ` AdaMagica
2023-05-13  0:28 ` Rod Kay

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