int main( int argc, char* argv[] ) { // Our progress counter. auto counter = pc::ProgressCounter::Create(); // Our tasks queue. TaskQueue tasks; // Produce the tasks. std::mt19937 rnd_device( (uint32_t)time( 0 ) ); for( int32_t task_id = 0; task_id < 680; ++task_id ) { auto goal = counter->ProduceGoal(); std::chrono::milliseconds interval{ 600 + rnd_device() % 1400 }; tasks.PushTask( { [goal, interval](){ std::this_thread::sleep_for( interval ); } } ); }; // Produce the workers. tasks.Lock(); size_t threads_count = std::thread::hardware_concurrency(); while( threads_count-- > 0 ) { std::thread t( ThreadFunction, std::ref( tasks ) ); t.detach(); }; tasks.Unlock(); // Display the progress of tasks completion until the progress reaches 100% do { printf( "\rCurrent progress : %3.3f%%; Tasks remained : %zd;", 100.0f * counter->GetFinisedPercent(), tasks.GetCount() ); std::this_thread::sleep_for( std::chrono::milliseconds( 500 ) ); } while( counter->GetRemainsPercent() > 0.0f ); };