Hi,

How to find the stack size available for main thread in a program(which contains the main() function)

In the case of linux, we can specify the stack size available for the whole program in linker script during linking. For all other threads, we can specify the stack size when creating the thread . But how is it done for main thread?

The stack size you specify in the makefile for linking is only for the main thread. It does not include the other threads that the program may create during runtime.

Here are other suggestions.

Edited 6 Years Ago by Ancient Dragon: n/a

The stack size you specify in the makefile for linking is only for the main thread. It does not include the other threads that the program may create during runtime.

Here are other suggestions.

if that is the case, i would like to know some more things about the memory allocation [ie,stack/heap boundaries]

How the program will allocate the stack areas for the threads that it is going to be created at run time. I mean to ask that where it will get allocated [in which part of memory? how the program will know the address range where it has to allocate the stack]? If only the main thread stack area[or address range] is specified during linking, the run time thread stacks could get allocated at different places of the memory. I was thinking that the stack is contiguous memory location[ including the stack areas of all the threads].
Also, how the program will know the the limits of heap area of memory? If some one can clarify these in detail, i will be grateful..

thanks in advance

How the stacks are allocated is compiler and operating system dependent. The stacks for all threads might be in contiguous memory, but then again they may not. When a new stack is needed the program will ask the operating system for a block of read/writeable memory, then use it as stack. The operating system doesn't know, or even care what the program uses the block of memory for.

Here is an explaination for how VC++ checks stack

This article has been dead for over six months. Start a new discussion instead.