Skip to content

Is accessing different elements of an array thread-safe? #451

@parmi93

Description

@parmi93
char my_array[10];

Let's say threadA changes the value of my_array[0] and threadB changes the value of my_array[1] , is this thread safe?

My instinct tells me that it is not thread-safe, because since arrays cannot have padding bytes between elements, and usually CPU access (read/write) multiple bytes at a time, that means changing the value of my_array[0] would result in writing adjacent array elements which may have changed in the meantime.

More specifically, is this guaranteed to be thread-safe with single core MCUs without cache?

And if this is thread-safe, is this guaranteed by the CPU or by ThreadX?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghardwareNew hardware or architecture support request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions