DEV Community

Cover image for Thread in C (Codexion 42)
Yassir El bakkari
Yassir El bakkari

Posted on

Thread in C (Codexion 42)

Imagine a quiet workshop.

One worker enters.

His name is main thread.

He has one notebook (stack), one pair of hands (registers), one path to walk (instruction pointer).

He reads instructions one by one from the program text section.
Everything is calm. Deterministic. Linear.

Then work increases.

The workshop manager says:

“We need more workers.”

And we call:
pthread_create(...)

CHAPTER 1 — BIRTH OF A THREAD
pthread_create is not magic.

It is a negotiation between your user-space library and the kernel.
What the pthread library does first
Before asking kernel, libc/pthread prepares:

Top comments (0)