I have three separate threads that get the same object. Each of the threads has different values.
class ClassA{
int counter_a = 0;
int counter_b = 0;
int counter_c = 0;
void startCounterA() {
this->counter_a++;
}
void startCounterB() {
this->counter_b++;
}
void startCounterC() {
this->counter_c++;
}
};
ClassA a;
std::thread pt(&ClassA::startCounterA, a);
pt.join();
std::thread ct(&ClassA::startCounterB, a);
ct.join();
std::thread mt(&ClassA::startCounterC, a);
mt.join();
When the threads finish running all the values is zero. why? how can I solve it?