Determine the number of threads dynamically.