Hi,
I want to use static member variable to monitor the execution state,
but I am not sure this is multi-thread or multi task safe. Here is my
class:
calss MyClass{
static int numCandidates;
public:
MyClass();
int func();
};
MyClass::MyClass(){
... get a list of candidate algorithms...
... set the size of the list to numCandidates...
}
int MyClass::func(){
If (numCandidates > 0){
... try the nth candidate algorithm...
--numCandidates;
...return algorithm result...
}
return -1;
}
main(){
MyClass::numIns = 0;
MyClass c;
int r;
while ((r=c.func()) != -1){
... some analysis of the algorithm result ...
}
}
You can see that I use MyClass::numCandidates to monitor the current
algorithm. My question is if these is any hole for this when there are
multiple copies started at the same time? Will each program has its owm
copy of MyClass::numCandidate?
Thanks.