CreateThreadsWithSmallerThanMinStackSize() Ĭonsole.WriteLine( "Cleanning up Threads. Private static List _threads = new List() Ĭonsole.WriteLine( "Creating Threads. Now running the same application multiple times on different machines with different configs will give a close or similar results. Running the following code on my virtual machine with the specs in the image runs around ~ 1400 Threads, the available memory on the machine also takes place in deciding the Max number of threads can be allocated to your process. that allow around 2000 thread per process (2000 * 1MB = 2GB).
The secret behind that is the default stack size is 1MB and the user-mode address space assigned to the windows process under 32 bit Windows OS is about 2 GB. When you create new thread, it has some memory in the kernel mode, some memory in the user mode, plus its stack, the limiting factor is usually the stack size.
with the simulation running more than 3000 individuals at the same time, it wasn’t too log before I got the OutOfMemory Unfriendly Exception. I needed to have a different thread for each person in the facility to simulate parallel and different movement of people at the same time. I was working lately on some mass facility simulation applications to test some complex RFID based system. while in fact the limitation is due to the amount of address space each thread have can have. Developers usually thinks that Windows has a default value for the max number of threads a process can hold.