Delphi TParallel Cleanup Needed


Tasks / Threads created by TParallel are more or less persistent which might be good for reusability. However, I would like to see a class method for cleaning up.

TParallel.For(0, 20, (procedure(A : integer) begin writeln(A) end));

The above code leaves threads behind, which can be observed with task manager.

Would creating your own TThreadPool instance and disposing of it when no longer needed satisfy you…?

var
  Pool: TThreadPool;
begin
  Pool := TThreadPool.Create;
  try
    TParallel.For(0, 20, (procedure(A : integer) begin writeln(A) end), Pool);
    Write('Disposing of the thread pool - press ENTER to continue...');
  finally
    Pool.DisposeOf;
  end;
end;

The thread pool remains existent for efficient reuse. A TThreadpool is recommended when explicit management of the threads is desirable.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
177 words
Last Post: QuickhostUK - WordPress - Brute Force Amplification Attacks Against XMLRPC
Next Post: Simple Parallel.For Implementation at Delphi 2007 without Generics and Anonymous Methods

The Permanent URL is: Delphi TParallel Cleanup Needed

Leave a Reply