r/programming • u/iximiuz • Aug 05 '26
Linux Processes: Threads & Concurrency
https://labs.iximiuz.com/tutorials/linux-processes-threads-concurrency-3302b677
93
Upvotes
r/programming • u/iximiuz • Aug 05 '26
View all comments
Show parent comment
18
u/Arnavion2 Aug 05 '26 edited Aug 05 '26
The start of a stack is just a pointer. It can be anywhere in memory.
The main thread's stack pointer is set by the binary loader. For ELF binaries the loader will reserve space for the stack, set the stack pointer register to the start of that space, and then jump to the binary entrypoint. For spawned threads, the thread spawning API will reserve some space for the new thread's stack, set the stack pointer register to the start of that space, and then jump to the thread entrypoint.
(Note: "Start of the stack" is often the highest address of the stack, not the lowest, because on many architectures the stack grows "downward", ie starts from the high address end and grows towards the low address end.)