Thread stacks

We understand that whenever a thread is created, it acquires a new, freshly allocated piece of memory for its stack. This leads to the understanding that (obviously, but we shall state it nevertheless) all local variables declared within a thread function will remain private to that thread; this is because they will reside in that thread's stack. (Refer back to Fig 2 in this chapter – the new stack of the newly created thread is shown in red). Also, whenever a context switch occurs, the Stack Pointer (SP) register is updated to point to the current thread's stack.

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.