c# – Maximum number of simultaneous streams

Question:

How many threads can you create that run simultaneously?

Answer:

There are several "concepts" for a process / thread.

Physically – no more than the number of processor cores. Those. if the processor is 4-core, it cannot execute more than 4 threads at the same time. There is Hyper-threading technology, the essence of which is optimization of "switching" between processes, i.e. Hyper-Threading 4-8 does not mean that 8 are executed simultaneously, but means that switching between threads is organized in such a way that it seems that there are more cores.

Logically (OS level) – until the memory of the handles runs out (i.e. a lot). Your question boils down to the maximum number of handles (since each thread needs to be assigned a handle), then the answer is up to 10,000 (minus 300 pieces are used by the system). The OS "converts" active handles into tasks, and the processor chooses by hardware decision which task to execute now at the hardware level. Handles can be files, pipes, event, mailslot and other OS objects. If the program actively uses handles (for example, a file is opened for each thread), then the handles will run out twice as fast, because the total number of khans should not exceed 10,000.

DOT NET level. In Thread #, a Thread is an object behind which there may or may not be a real Thread Handle. In addition, handles are pooled (for reuse). The active Thread is always backed up by the OS Thread Handle, but inactive threads can be created – until the Heap memory runs out. When exceeding a specific number of active Thread – we obtain an error that is not possible to create Handley.

Hardware level. TSS or Task Gate Descriptor For 32 bit processors, there is a GDT catalog – a table of tables with 8192 cells. In each, you can save a link to 8192 LDT elements, one of which can be a handle to the Task process (a part of the Thread without which the processor will not be able to hardware switch Thread. That is, 67 108 864 is the "theoretically" limit of hardware places for threads, but … you need to take into account that memory descriptors also need to be placed in this table, ie minus memory descriptors … will come out from a million to 60 million. But in reality, there is a limit above which the processor will be "nothing else busy except for switching processes ", therefore … they do not use so much. The processor distributes these tasks between the cores with a hardware solution. What the OS will do when they run out – most likely the OS has a built-in constant limit on the number of tasks, since with too many of them the processor will begin to lose performance.

Hardware links:

Scroll to Top