lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Sep 6, 2021 at 7:18 PM Lorenzo Donati
<lorenzodonatibz@tiscali.it> wrote:

> For example, assuming x and y are 16 bit quantities on an 8 bit MCU,
> if you write:
>
> x = <expr1>;
> y = <expr2>;
>
> there is no way in C99 to ensure that the updating of x happens
> completely before the updating of y (the upper 8 bits and the lower 8
> bits of each can be modified in any order-usually for optimization
> purposes).

Unless you are talking about setting x and y from two different
threads, and unless you also need to be wary of
interrupts/signals/etc, it is enough to have x and y marked as
volatile in C99.

In later versions, atomics might be a better choice.

Cheers,
V.