Each thread keeps its own program counter, stack pointer and registers, while sharing variables.
Circle one: True False
What do threads inside one process share?
- One address space with the same variables
- Separate private memories each
- Nothing, they are fully isolated
Why is creating a thread cheaper than creating a process?
- Threads skip all safety checks
- A thread reuses the existing address space
- Threads run on faster hardware
One thread waits for a slow disk while another keeps computing. What does this show?
- The cost of sharing memory
- The gain of threads: work continues while one part waits
- That waiting threads use no memory
Two threads both run total = total + 1 on a shared counter. Which variable can both reach at once?
- total, since it sits in shared space
- Only each thread's own program counter
- Neither, threads cannot share variables
What makes switching processes cost more than switching threads of one process?
- Threads never need the CPU at all
- Processes share everything, threads share nothing
- The shared space stays put for threads, but processes swap address spaces
You want the speed of sharing without the collisions. What is the best fix?
- Give every thread a fully private memory
- Stop using threads entirely
- Let only one thread change the shared data at a time
Two threads each raise a shared counter 1000 times, but it ends near 1000 instead of 2000. What happened?
- The counter overflowed its memory
- The threads stepped on each other and raises got lost
- The threads ran on separate address spaces