What is a Thread?
Think Of It Like Roommates
Threads are like people living in the same apartment. They share the kitchen, living room, and bathroom. If one roommate puts milk in the fridge, others can grab it. No walls between them.
Each roommate has their own personal stuff though - their own bed, their own backpack. For threads, this is the stack (local variables) and registers.
Why Sharing Is Fast
Creating a roommate is cheap: Making a new thread takes 10-100 microseconds - about 100x faster than creating a new process. No new apartment to set up.
Talking is instant: One thread writes to a variable, another reads it immediately. No copying, no OS involvement.
Switching is quick: Moving between threads takes 1-10 microseconds - about 10x faster than processes.
Why Sharing Is Dangerous
No privacy: Any thread can read or write any shared variable. If two threads update the same data without coordination, chaos ensues.
One bad roommate ruins everything: If one thread crashes or corrupts memory, all threads in the process go down together. There are no walls to contain the damage.