Right. But if there's only a single call to tbb::task_scheduler_init(), only a single market is created, with the max_num_threads specified by that single call. In that case, a sole arena is created, with the same num_threads value and so that min() is really a no-op. Now, the situation is different with multiple calls to tbb::task_scheduler_init(), but it still doesn't change the fact that setting the amount of worker threads to be less than num_cores-1 is not possible as-is.
We traced through the code and confirmed exactly the behaviour I reported. We have also patched it locally, and now it works as advertised (see Table 41 in the Reference Manual), but we'd rather not have to maintain that patch for the indefinite future.
Table numbers vary across versions of the Reference Manual, so I don't know which one you are referring to?
In a real program, the same number of worker threads is created as is specified in the max_num_threads argument to task_scheduler_init, less one. As noted in my case, if I specify 1000 threads, 999 worker threads get immediately created the moment the first task is issued. This can be easily verified on Linux (either in gdb or by running top), and in Windows by monitoring the number of threads in the task manager.If that doesn't help, please describe exactly what goes wrong in a real program.
In the current implementation, threads are always created lazily, but there can be situations when extra threads are created. As far as I recall, the total number of threads cannot be bigger than what the market can maintain, i.e. that verymaximum of HW concurrency and the very first arena size.
I've completedthree tests ona 32-bit Windows XPand I couldn't reproduce the issue. Could you provide a simple Test-Case?
I tried to create 256, 512 and 1024 threads and results are as follows:
- Attempt to create 256 threads: 258 threads created (1 main process thread + 256 TBB threads+ 1 unknown thread )
- Attempt to create512 threads:514 threads created (1 main process thread +512 TBB threads+ 1 unknown thread )
- Attempt to create1024 threads:986 threads created (1 main process thread +984 TBB threads+ 1 unknown thread ) Note: Failed to create 1024 TBB threads
Here isa screenshot for the512 threads Test-Case:
Two more screenshots are attached.