Please consider the following scenario.
class A that holds 3 variables:
Class A
{
public:
// ctor, getters, setters, etc...
private:
uint8_t x;
uint8_t y;
uint16_t z;
}
class B that holds variable of type A:
Class B
{
public:
// probably some good stuff too...
private:
A a;
}
There is a function running on a separate thread that modifies object a
's variables: x, y and z.
And there is a function running on a gui thread that will have to read object a
and display it's variables to user.
Apparently that will cause data race or some other bad things.
How to fix this scenario?
To make object a
atomic? Or object a
's variables: x, y and z atomic? Or both?...
Regards, Mike.
Aucun commentaire:
Enregistrer un commentaire