4 - Threads Flashcards
Define Threading:
Multiple threads of execution within a single process.
Is forking a process efficient? If not, why?
No, because it copies everything.
Define a Thread:
A tread is a basic unit of CPU utilization.
Do Threads of a process have their own separate memory or share memory together?
Threads of a process share memory but can execute independently.
In Web Servers, why is Forking inefficient compared to threading other than because it copies everything?
Web serveres have caches for read pages - forking means that these caches cannot be shared. Threads allow for these caches to be shared.
What do threads share?
- Process Address space (text, data, heap)
- OS State (open files, sockets, locks)
What do threads not share?
They have their own CPU context:
- Program counter, Stack pointer, register state, stacks
Give 4 benefits of threads:
Responsiveness
Resource Sharing
Allocating memory and resources for process creation is costly which is avoided.
Context-switching is faster
What does a thread library provide for the programmer?
An API for creating and managing threads
What are the 3 main libraries?
1) POSIX Pthreads
2) Win32
3) Java
True or false: Threads also share global variables which is a another pros.
False; sharing global variables is dangerous