我最近比较了.NET中的OmniThreadLibrary和ThreadPool,我发现Omni在最大线程中受到更多限制 – 允许60 – 而.NET在.NET 4.0中可以达到32768.
为何如此限制?
解决方法
这是一个历史性的选择,曾经可能被解除.限制仅适用于线程池实现.
对the website给出了解释,说明如下:
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.
这个限制的原因是深层内部[OtlTaskControl] TOmniTaskExecutor.WaitForEvent使用具有此限制的MsgWaitForMultipleObjectsEx.如果对具有超过60个并发运行线程的任务池实际需要,则可以规避此限制.