I have the following function that I use as an entry point for a windows fiber.
void foo(void*) {
for(int i =0; i < 10; ++i) { doStuff(); }
}
Now I call SwitchToFiber in my main in a for loop; something like the following.
int main() {
... create the fiber and stuff
for (int i = 0; i < 50; ++i) {
SwitchToFiber(foo_fiber_ptr);
// how do I tell if foo has already finished execution?
// (without passing in a state variable to communicate.)
if (someCondition) { break; }
}
... do stuff
}
So my question is: how do I tell if foo has already finished execution?(without passing in a state variable or declaring a global state variable to communicate.)
Declare a global variable. After executing the
foofunction, change the state of the global variable infoo.In
maincheck for the state change. If the state of the global variable is changed, meansfoohas already been executed.