libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.29k stars 903 forks source link

Thread Pool Fix High CPU Load When Paused #1039

Closed COM8 closed 2 months ago

COM8 commented 2 months ago

Fixes #1035.

Switched from a yield based approach to a conditional variable based approach. Now all threads paused inside a thread pool are properly paused and do not consume a lot of CPU cycles while waiting.

With this PR I'm also adding additional Thread Pool test cases. They are disabled right now since there is a bug causing them to get stuck inside the:

task_cond.wait_for(locker, std::chrono::milliseconds(max_idle_time), [this]() { return status == STOP || !tasks.empty(); });

Probably the notify is not working correctly here. This will be fixed by a follow up PR.