What is a thread?
A lightweight process that represents the smallest unit of CPU execution with its own program counter, registers, and stack, but shares code and data with other threads in the same process.
What is the main difference between a process and a thread?
A process has its own memory space; threads within a process share the same memory space.
What do threads share in a multithreaded process?
Code section, data section, and open files.
What resources are unique to each thread?
Program counter, registers, and stack.
Why do modern applications use threads?
To increase responsiveness and efficiency by performing multiple tasks concurrently within a single process.
What does responsiveness mean in multithreading?
One thread can continue executing even if another is blocked (e.g., waiting for I/O).
How does multithreading support resource sharing?
All threads share process resources so they can communicate easily without inter-process communication overhead.
Why is thread creation more economical than process creation?
Threads share the same address space, so creating them requires less memory and CPU overhead than a new process.
What does scalability mean in multithreading?
Threads can run on multiple processors simultaneously to improve performance.
Give an example of a multithreaded application.
A web server handling multiple client requests at once.
What are user threads?
Threads managed in user space by a thread library without kernel awareness.
What are kernel threads?
Threads supported and managed directly by the operating system.
What are the three main multithreading models?
Many-to-One, One-to-One, and Many-to-Many.
Describe the Many-to-One model.
Many user threads mapped to a single kernel thread; entire process blocks if one thread blocks.
Describe the One-to-One model.
Each user thread maps to a kernel thread; allows true parallelism on multiprocessors but is costly.
Describe the Many-to-Many model.
Multiple user threads mapped to a pool of kernel threads for flexibility and non-blocking calls.
What is the Two-Level model?
A variation of Many-to-Many that can behave as either Many-to-Many or One-to-One.
In which model does a blocking system call block the entire process?
Many-to-One.
In which models can multiple threads run concurrently on a multiprocessor system?
One-to-One and Many-to-Many.
What is a thread library?
An API that provides functions for creating and managing threads.
Name three common thread libraries.
Pthreads (POSIX), Win32 threads, and Java threads.
What does pthread_create() do?
Creates a new thread and assigns it a function to execute.
What does pthread_join() do?
Makes the calling thread wait for another thread to finish execution.
What is the purpose of pthread_exit()?
Terminates the calling thread without ending the entire process.