In C#, you can limit the number of threads, like this:
Parallel.For(0, 10, new ParallelOptions { MaxDegreeOfParallelism = 4 }, count =>
{
Console.WriteLine(count);
});
Does Delphi have this in latest compiler e.g. Berlin. Or does the omnithreadlibrary have this?
Use the Parallel.For
overload that accepts a TThreadPool
, and supply a thread pool that limits the number of threads. That is done with the SetMaxWorkerThreads
method.
Note that I obtained this information by reading the documentation.