简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM