Skip to content

thread-pool v1.2

Choose a tag to compare

@bshoshany bshoshany released this 30 Apr 16:51
· 19 commits to master since this release
  • Version 1.2 (2021-04-29)
    • The worker function, which controls the execution of tasks by each thread, now sleeps by default instead of yielding. Previously, when the worker could not find any tasks in the queue, it called std::this_thread::yield() and then tried again. However, this caused the workers to have high CPU usage when idle, as reported by some users. Now, when the worker function cannot find a task to run, it instead sleeps for a duration given by the public member variable sleep_duration (in microseconds) before checking the queue again. The default value is 1000 microseconds, which I found to be optimal in terms of both CPU usage and performance, but your own optimal value may be different.
    • If the constructor is called with an argument of zero for the number of threads, then the default value, std::thread::hardware_concurrency(), is used instead.
    • Added a simple helper class, timer, which can be used to measure execution time for benchmarking purposes.
    • Improved and expanded the documentation.