More threads will not necessarily give you higher throughput.
Threads have a non-trivial cost, both to create (in terms of CPU
time and OS resources) and to run (in terms of memory and
scheduling). And the more threads you have, the more potential
for contention with other threads. Adding threads can sometimes
even slow down execution. Each problem is subtly different, and
you are best off writing a nice, flexible solution and
experimenting with the parameters to see what works best. Your
example code, spawning a thread for each file, would almost
immediately swamp the system for values of max_threads beyond
around 10. As others have suggested, a thread pool with a work
queue is what you probably want. The fact that each file is
independent is nice, as that makes it almost embarrassingly
parallel (save for the aggregation at the end of each unit of
work). Some factors that will affect your throughput: - Number
of CPU cores - The number of disk channels (spindles, RAID
devices, etc) - The processing algorithm,