On Mon, 15 Jul 2019 11:49:56 -0500 Wes McKinney <wesmck...@gmail.com> wrote: > > For example, suppose we had a thread pool with a limit of 8 concurrent > tasks. Now 4 of them perform IO calls. Hypothetically this should > happen: > > * Thread pool increments a "soft limit" to allow 4 more tasks to > spawn, so at this point technically we have 12 active tasks > * When each IO call returns, the soft limit is decremented > * The soft limit can be constrained to be some multiple of the hard > limit. So if we have a hard limit of 8 CPU-bound threads, then we > might allow an additional 8 tasks to be spawned if a CPU bound thread > indicates that it's waiting for IO
Well, there are two approaches to this: * the approach you are proposing * the approach where IO is done in separate worker threads so that we needn't resize the main thread pool when IO is done Advantages of the second approach: * No need to dynamically resize the main thread pool (which may difficult to achieve in an efficient manner). * CPU-bound threads can stay pinned on the same HW cores and threads most of the time, which is probably good for cache locality and to avoid migration costs. Advantages of the first approach: * The programming model is probably simpler. Also, the first approach is not workable if e.g. TBB doesn't support it (?). Regards Antoine.