TRT
Sign in

Advanced · Module 7 · Lesson 1 of 8

Thread Lifecycle: pthread_create, pthread_join, and Thread Stacks

Launch concurrent execution threads within a shared address space using pthread_create, synchronize exits with pthread_join, inspect thread stack allocations, and eliminate stack lifetime hazards.

Pro — members onlyAbout 16 minutes

By the end you can

  • Spawn concurrent threads of execution using pthread_create with type-safe argument payloads
  • Synchronize thread termination and capture return pointers using pthread_join and pthread_detach
  • Inspect thread memory layouts: shared heap and global state versus private stacks and guard pages
  • Eliminate stack escape defects where thread arguments or return values reference destroyed stack frames

Builds on Process Synchronization with POSIX Semaphores.

01 · A question first

Why does passing a pointer to a loop variable &i into pthread_create() cause every thread to print the exact same number or crash unpredictably? And how does the kernel isolate thread stacks while letting every thread freely mutate the same global variables?

Make a guess before you read on.

02 · The idea

Members only

Unlock the full lesson

This lesson is part of the membership. Join to read it in full, along with every other premium deep dive.

What's inside

  • Start with the problem
  • How the idea works
  • Why it is correct
  • What it costs
  • Pitfalls and variations
  • Where it is used

03 · Practice

Something wrong with this lesson? Report a problem