From https://github.com/rayfung/task_scheduler/blob/master/main.cpp