We don't need to spawn a new thread to wait on another thread to shut down. We can use a condition variable to synchronize the threads. (Conceptually), the exiting thread sets the variable and the parent waits on that event.
I abstracted that into a OnceFlag (better names are welcome). It's a flag that can be set and waited on. The tests involve some timing measurements because we want to wait for some time and "not wait for some time" when the flag is already set.
We don't need to spawn a new thread to wait on another thread to shut down. We can use a condition variable to synchronize the threads. (Conceptually), the exiting thread sets the variable and the parent waits on that event. I abstracted that into a
OnceFlag
(better names are welcome). It's a flag that can be set and waited on. The tests involve some timing measurements because we want to wait for some time and "not wait for some time" when the flag is already set.