How Stack and Heap is allocated for threads under the same process in Windows

multithreadingoperating systemswindows

Stack for different thread is different.but what about Heap. If Heap is different for different threads, then how they share objects?

Best Answer

The standard implementation for operating system threads is that they share the same memory (i.e. heap), code, data, resource handles etc. Code using this kind of threading can share objects (although you should then be asking "How do they share objects safely?"). However, some languages (e.g. Erlang) offer their own version of threads which do not have access to shared memory. In such cases, there is no shared state and therefore no shared objects; these constructs communicate by some form of message passing.