MankPan
MankPan

Reputation: 124

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?

Upvotes: 4

Views: 2278

Answers (2)

user3344003
user3344003

Reputation: 21607

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

The former is true. The latter is false. Processes frequently have multiple heaps, especially when linking in 3d party code.

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

Per thread.

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

Typically they will remain allocated to the process until the process exits and the address space no longer exists.

Upvotes: 1

Jeremy Friesner
Jeremy Friesner

Reputation: 73041

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.

Upvotes: 6

Related Questions