Lunar Mushrooms
Lunar Mushrooms

Reputation: 8968

Pthreads: Relation between main thread and subthread stack sizes

I am trying to understand the stack allocation of pthreads library in Linux. Here are few questions:

A) What is main thread ? - Is that the thread running C main() program?

B) How much is stack allocation of main threads? Is that the ulimit -s size ?

C) How much is stack allocation of sub-threads? Is that the ulimit -s size ?

D) The stack size of main thread and other threads are dependent ?

E) The process stack and thread stack are shared? How do I decide process stack (say a.out) size.

F) Does these information vary between NPTL and LinuxThreads implementation?

Thanks

Upvotes: 0

Views: 818

Answers (1)

Employed Russian
Employed Russian

Reputation: 213955

A: Yes
B: Yes
C: Maybe.

If pthread_attr_t used at thread creation did not specify stack size, and if ulimit -s is not unlimited, then ulimit -s will determine the stack size of a newly created thread.

D: Question is unclear. They are not dependent on each other, but they do both depend on ulimit -s under certain conditions.

E. Yes and no. They are shared in the sense of memory visibility -- the main thread can read and write other thread's stack variables, and vice versa. But each thread executes on its own stack, and if ever two threads started to execute on the same stack, that would be a disaster.

F. No.

Upvotes: 1

Related Questions