M
Moshbear dot Net
Given
class Fred {
public:
Fred() {
ctr = ++xctr;
}
....
private:
unsigned ctr;
static unsigned xctr; // initialized via boost::thread::run_once
....
};
,
what would be the best way to make the increment-and-read of xctr
atomic so that it is thread-safe?
I'm using xctr to track instance number of class so that I can use
operator<(const Fred&) to compare by instance-creation time.
class Fred {
public:
Fred() {
ctr = ++xctr;
}
....
private:
unsigned ctr;
static unsigned xctr; // initialized via boost::thread::run_once
....
};
,
what would be the best way to make the increment-and-read of xctr
atomic so that it is thread-safe?
I'm using xctr to track instance number of class so that I can use
operator<(const Fred&) to compare by instance-creation time.