I have a struct with some integers field, like
struct s {
int a;
int b;
int c;
int max;
};
struct s mystruct = {0, 0, 0, 0}; // Global var
And then I have N threads that sometimes have to do things like ++
or --
on the first three fields, and sometimes have to read them and then update the max
field. Do I have to use a mutex here? And if yes, is it needed only when reading/updating max
or always? Why? If I just increment or decrement the first three fields, does it matter if a thread runs before another?