I have found similar questions to the one I have (i.e. Is changing a pointer considered an atomic action in C?), but I have not been able find anything that gives me a definitive yes/no answer when it comes to writing a pointer.
My problem is thus. I have an array of struct pointers with a pointer field.
For example
struct my_struct {
void *ptr;
};
struct my_struct *my_struct[10];
The pointer fields of each struct is read and written to by a thread.
For example
uint8_t index;
for(index = 0; index < 10; index++)
{
if(my_struct[index]->ptr != NULL)
{
my_struct[index]->ptr = NULL;
}
}
Periodically an interrupt occurs that will read (does not write and I can't use a lock because the handler is time critical) one or more of the pointers stored in my array of structs.
For example
void *ptr = my_struct[2]->ptr;
Ultimately I do not care about whether the pointer read by the interrupt handler is new or old; only that it hasn't been corrupted. Clearly, the following operation will not be atomic
my_struct[index]->ptr = NULL;
But, can I be sure that if an interrupt occurs and reads "my_struct[index]->ptr" it will not be corrupted? I suspect that this should be true since (1) a pointer should completely fit into a register (at least for my target, MSP430) and (2) writing a single register is most likely an atomic instruction. Is my reasoning correct?