It's your job to limit the number of threads you spawn.
As for the memory they use, except from the stack (I'll get back to that just below) it is totally indistinguishable from the rest of your program. Actually that's the whole point of using threads instead of multiple processes (fork
in Unix parlance): they all share the same memory. Since any allocation made by a thread is seen by the OS as coming from your process (and not from a specific thread) you can't artificially limit the memory usage of a single thread.
Concerning the stack memory which is allocated to each thread: you may want to read this answer of mine about this topic (especially the first point), hopefully you will realize it is pointless to try to reduce the stack size of your threads.
So, to sum it up, threads are like any other part of your program: you can't put a hard limit either on their number or on the quantity of memory they are allowed to allocate (within the bounds of what your machine can handle, of course). Again, it's your job as a programmer to manage the resources correctly, not the compiler's job, not the OS's job.
You want less than 10000 threads? Then just don't spawn them in the first place. You want them to use less memory? Then don't allocate that memory in the first place. All you have to do is put the necessary safeguards in your code.