0
votes

There is a separate stack created for each pthread in process userspace when pthread_create() is used

Does it mean that if I call pthread_create() inside main() N times, then the number of actual threads within the process and correspondingly the number of stacks within userspace will be N + 1 ?

I'm just confused by this pic

https://computing.llnl.gov/tutorials/pthreads/images/thread.gif

because it does not show any stack for main()

Thanks

1

1 Answers

1
votes

main() is a thread too. If it was not, it would have no execution and so could not do anything:)

So, yes. If you create N threads in main(), you end up with N+1 threads and, so, N+1 stacks.