C11 supports atomic operations. Unfortunately, most compilers do not support C11 atomics, but you can them for example with GCC 4.9:
#include <stdatomic.h>
struct mystruct
{
_Atomic int a;
...
};
int load(struct mystruct* s)
{
return atomic_load(&s->a);
}
void store(struct mystruct* s, int value)
{
atomic_store(&s->a, value);
}
Note that it is not sufficient to protect only write operations. The C11 standard is pretty clear about that. If two threads can access the same memory location at the same time, and at least one of the operations is a write access, then the behaviour of the program is undefined. That means you have to protect all accesses.