Skip to content

Instantly share code, notes, and snippets.

@tmathews
Created December 11, 2024 17:10
Show Gist options
  • Save tmathews/ecffc79c80567aaa8e7b462937980320 to your computer and use it in GitHub Desktop.
Save tmathews/ecffc79c80567aaa8e7b462937980320 to your computer and use it in GitHub Desktop.
struct WaitGroup {
std::atomic_int counter = 0;
void add(int i)
{
counter += i;
// printf("COUNTER[UP]: %d\n", counter.load());
}
void done()
{
counter--;
// printf("COUNTER[DN]: %d\n", counter.load());
assert(counter.load() >= 0);
}
void wait(std::function<void()> fn)
{
// TODO add time out to WaitGroup functionality?
while (counter > 0)
{
fn();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment