Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The max_threads parameter of async::startup is not affect #1195

Open
portsip opened this issue Mar 8, 2025 · 1 comment
Open

The max_threads parameter of async::startup is not affect #1195

portsip opened this issue Mar 8, 2025 · 1 comment
Labels
Milestone

Comments

@portsip
Copy link

portsip commented Mar 8, 2025

Description

I've tried the below settings: cpr::async::startup(4,10);
But if launching massive POST requests to the CPR at the same time, after a while, the cpr::GlobalThreadPool::GetInstance()->GetIdelThreadm() output the value is greater than the 10.

I've taken a look at the source code, I think there needs to be a lock added when determining the thread numbers to create a new thread if the Submit is called concurrently:

    auto Submit(Fn&& fn, Args&&... args) {
        if (status == STOP) {
            Start();
        }
        if (idle_thread_num <= 0 && cur_thread_num < max_thread_num) {
            CreateThread();
        }

Example/How to Reproduce

Just launching massive POST requests at the same time, then after a while, output the cpr::GlobalThreadPool::GetInstance()->GetIdelThreadm() .

Possible Fix

No response

Where did you get it from?

conan

Additional Context/Your Environment

  • OS: Windows 10, Debian 12
  • Version: Windows 10, Debian 12
@COM8
Copy link
Member

COM8 commented Mar 20, 2025

Fixed by: #1168

@COM8 COM8 added this to the CPR 1.12.0 milestone Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants