[chbot] Chchrobotics Digest, Vol 173, Issue 1

Bevin Brett bevin_brett at hotmail.com
Sat Feb 5 07:15:31 GMT 2022


I am not clear whether your volatile is a file level or function level variable
i.e. does your code look like this...

BEFORE

    Data buffer[buffersize];

    void func() {

        volatile S v = { buffer, m2, ... };

    }

AFTER

    void func() {

        volatile S v;

         v.m1 = buffer;
         v.m2 = m2;
         ...
         tell_someone_they_can_use_v_to_access_buffer(&v);

    }

OR like this

    Data buffer[buffersize];
    volatile S v; // old code = { buffer, m2, ... };

    void func() {
        // new code
         v.m1 = buffer;
         v.m2 = m2;
         ...
         tell_someone_they_can_use_v_to_access_buffer(&v);
    }

Which is v?   a global or a function local?

Perhaps you have a race between the initialization and use of v.

The initialization of non-function statics and globals happens in C++ in a somewhat  unpredictable order, but before main() is called, as the complicated description you linked to describes.

Also I suspect buffer should be volatile.

/Bevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20220205/babbb4d1/attachment-0001.html>


More information about the Chchrobotics mailing list