Search code examples
cmultithreadingmemory-managementvirtual-memorymemory-layout

Maximum size of stack of multi threaded process


As per my understanding

  1. each thread of a process gets a stack, while there's typically only one heap for the process.
  2. There is default stack max size limit set by OS.

    1. Windows-64 bit : 1MB
    2. Linux-64 bit : 8MB

Is this limit applicable at process level or each thread can have 1MB/8MB stack?

And what happens to the memory allotted to stack after thread exit?


Solution

  • each thread of a process gets a stack, while there's typically only one heap for the process.

    That's correct.

    Is this limit applicable at process level or each thread can have 1MB/8MB stack?

    Each thread gets its own stack; the stack-size-limit is per-thread (i.e. it is not a shared limit for all threads in the process)

    And what happens to the memory allotted to stack after thread exit?

    The memory pages are released and become available for use by other code in the future.