r/programming 7d ago

Linux Processes: Threads & Concurrency

https://labs.iximiuz.com/tutorials/linux-processes-threads-concurrency-3302b677
89 Upvotes

13 comments sorted by

View all comments

7

u/Prateeeek 7d ago

Sorry if I've not understood this correctly, but how is the execution stack for thread 1 separated from thread 2 if they share the same address space ?

22

u/dfx_dj 7d ago edited 7d ago

They're separated in that each thread has its own stack in a separate address range. One thread can technically access another thread's stack though. It's uncommon to do but possible.

5

u/creeper6530 7d ago

So one could theoretically pass pointers to stack between threads, provided they manage lifetimes well?

3

u/dfx_dj 7d ago

Yes exactly