Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recursive pthread spawning - stack location

I'm playing around with pthreads, now it seems to me, that when i call pthread_create from a thread that was previously spawned with pthread_create, the stack for the new pthread will be allocated on the stack of the father thread. In the main-thread, this would not be a problem, because the main thread's stack can still grow, as the MMU will allocate and map new memory for it when neccessary, but a pthread has a fixed stacksize. So when i create a pthread from a pthread, I have to make sure that the father-pthread's stacksize (and guardsize) is large enough to hold the child pthread's stack (plus guardpages).
Is that assumption correct? I haven't been able to find any documentation on this.

like image 590
user2950911 Avatar asked Dec 09 '25 19:12

user2950911


1 Answers

A parent-thread created using pthread_create() may create another child-thread using pthread_create().

If the the child's stack would live on the parent's stack then the child's stack would become invalid as soon as the parent ends, and the child couldn't live on.

The latter is not the case.

From this one can conclude the child's stack does not live on the parent's stack.

like image 114
alk Avatar answered Dec 12 '25 09:12

alk