Created
December 11, 2024 17:10
-
-
Save tmathews/ecffc79c80567aaa8e7b462937980320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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