Where is the task stack allocated in C #?

We all know methods like Task.Run or Parallel.ForEach. Each of them creates tasks that are performed in accordance with the parameters in a separate thread or in a thread from a thread pool. But where is their stack? In some heap of generation, or is there a special place for them?

For example, I can create 1000 tasks, and where do their stacks reside? Will their physical address move at some point if I call GC.Collect ()?

+4
source share
2 answers

The stack is a purely unmanageable implementation detail. The processor needs a stack to do something, it cannot run any code without problems without it. It is highly thread-bound, another unmanageable information about regular CLR hosts.

It is located in the memory where the OS kernel decided to allocate it when creating the stream, it is random. Intentionally randomly making malware difficult, the stack is an attractive way to turn data into malicious code. Not only a random location, but the exact offset within the stack segment where the start begins is random.

, GC . , . , - .NET, , CLR , . , . , - :)

+3

, , TaskScheduler, TaskScheduler. . ( ) .NET.

, Task.Run ​​ .

TaskCompletionSource . , - .

.NET " ". .

+2

Source: https://habr.com/ru/post/1650293/


All Articles