4

I was recently comparing OmniThreadLibrary and ThreadPool that is in .NET and I found that Omni is much more restricted in maximum threads — 60 allowed — while .NET can go up to 32768 in .NET 4.0.

Why such a limit?

  • 1
    there is possibly another reason. and that is stack size. the default in Delphi is to allocate 1MB of address space to the stack of each thread. on a 32 bit process you will run into issues around the 1000 thread count with out of memory exceptions being thrown, despite there being ram unused. this is due to the 2.1GB available address space of a 32 bit app. – Mike Taylor Nov 19 '12 at 19:37
  • @MikeT by the way this can be bypassed if you use multiprocess with IPC. Then you can have 60 + threads. –  Nov 19 '12 at 22:47

2 Answers2

8

It's an historic choice that once may be lifted. The limit is only there on the threadpool implementation.

An explanation is given on the website, stating the following:

The limitation of 60 concurrent threads only applies to the thread pool. Thread pool is designed for fast execution of many small requests, not as a storage for rarely-active threads.

You can just skip thread pool and use OTL tasks directly. That way you can create many hundreds of them.

The reason for this limit is that deep inside [OtlTaskControl]TOmniTaskExecutor.WaitForEvent uses MsgWaitForMultipleObjectsEx which has this limitation. If a real need occurs for task pools with more than 60 concurrently running threads, this limitation could be circumvented.

gabr
  • 26,580
  • 9
  • 75
  • 141
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • 1
    Btw, the link is dead. The OTL forum appears to be dead. – David Heffernan Apr 08 '14 at 09:26
  • Yes, unfortunately. There is an [issue report](https://code.google.com/p/omnithreadlibrary/issues/detail?id=59) for that, although I don't have any insights in if or when the forum will be restored. – GolezTrol Apr 08 '14 at 10:19
  • Am I right in saying this limitation applies to the Parallel.For/Foreach functions? If so, we would need to change our code to create the tasks manually because we require > 60 threads. Is there a straightforward way in OTL to wait for a collection of tasks to complete (WaitFor or similar)? – Alan Clark May 19 '15 at 19:09
1

You can bypass this stuff by changing the following:

FD_SETSIZE = 1024 in Winsock.pas

CMaxConcurrentWorkers = 1024; in OtlThreadPool.pas