Pile of thread and stack

How memory is allocated in case of a new thread, i.e. How are heap memory, memory stack, and threads related? I know that this is a fundamental concept (.net framework), but for some reason I do not really understand this concept.

+7
memory-management stack heap multithreading
source share
4 answers

It is very difficult to answer this question because of how .Net streams are implemented. There is not necessarily a 1-1 implementation between managed and corresponding native threads. The CLR can use multiple native threads to implement a single managed thread. Therefore, the allocation of a new managed stream does not necessarily lead to the emergence of its own stream. He can just assume the existing one.

Can you tell us why this bothers you? Perhaps this will lead us to a better answer.

+2
source share

The stack refers to the context of the thread. The heap belongs to the process, so it is shared between threads.

+1
source share

This is substantially deeper than .net. Themes are OS objects. What is called Managed Thread is just a wrapper around its own thread.

So, back to your question. A heap of memory is shared with threads of the same process because they are located in the same virtual memory space. Stacks are individual.

+1
source share

Each thread has its own stack, but all threads share a heap.

0
source share

All Articles