I use the command below to view the maximum number of threads my system allows:
# cat /proc/sys/kernel/threads-max
And the number is 772432
You should not print your unsigned long long with %d.
Use
printf("... %llu\n", thread_nr);
instead.