Reputation: 2232
Let there be a one-threaded programm, which calls a large functionLarge()
, which needs to finish before the next codeline in the callers main
Function. Assume the function is well broken down and just takes long.
In this answer .wait()
is suggested and I wonder if its better than:
bool done = false;
// returning true at the end, modifies bigObject by refrence
done = functionLarge(bigObject);
while(!done) { usleep(1000); }
//...can now continue
Are there better approaches, without the returning bool
?
Upvotes: 0
Views: 4338
Reputation: 385144
You're massively over-complicating this, because that's already how it works.
As you said, it's single-threaded. Control will be passed to functionLarge
and will not be returned until that function has completed.
You do not need to do anything. No need for any bool
s or while
loops. With a single thread, what is going to be doing the "waiting", exactly?
int main()
{
doThis();
nowDoThis();
}
Upvotes: 1