Skip to content
New issue

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

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

Already on GitHub? # to your account

Parallel.ForEach<> inside Parallel.Future<> seems to leak threads #184

Open
orthopteroid opened this issue Jul 11, 2022 · 1 comment
Open

Comments

@orthopteroid
Copy link

Symptoms:

  • 900+ threads created (only 1 per cpu expected nominally)
  • PostMessage related QUOTA errors (so, threads likely not getting enough time)

What seemed to be the problem was that threads were leaking from using code like:

bool:=Parallel.Future<boolean>(
  function(): boolean
  begin
    Parallel.ForEach<Integer>( list ).NumTasks( System.CPUCount ).Execute( delegate );
    result:=true;
  end );
while not bool.IsDone do
  begin
    Sleep(100);
    { update animated spinner }
  end;

In the end we eliminated the leak by removing the Future all-together, ie hoisting the ForEach up into the main thread, but we lose out on our nice spinner (for now).

Might it be possible that we could prevent the problem and use:

threadgroup:=Parallel.ForEach<Integer>( list ).NumTasks( System.CPUCount );

to create a context to hold the thread references (and allow the other compiler machinery to destroy them) and then use threadgroup inside the Future?

Alternatively, perhaps we will switch to a threadpool.

@achinastone
Copy link

See issue #194.
The memory is not leaking, but it seems that the memory has not been released immediately, and repeated calls can lead to memory depletion

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants