The problem is not Linux per se, it's the fact that pthread_create [1] reserves 2M for the stack, so the process runs out of memory if you have 1 million threads (1M * 2M == 2T)
[1] https://man7.org/linux/man-pages/man3/pthread_create.3.html
[1] https://man7.org/linux/man-pages/man3/pthread_create.3.html