Example code inspired by Anthony Williams's C++ Concurrency in Action