Threads Flashcards
Processes provide the abstraction of…
Threads provide the abstraction of…
Processes: an address space and resources
Threads: Execution states of that AS
PCB vs TCB, their locations, what data is stored
Process control block:
- Address space
- open files
- child processes
- pending alarms
> stored as kernel objects to protect them against unauthorized modifications
Thread control block:
- Instruction pointer
- registers
- stack
- state
>
Many to one model
=> User level threads
kernel only manages process -> multiple threads unknown to kernel
threads managed in user-space library
+faster thread management operations
+flexible scheduling policy
+few system resources
+can be used even if the OS doesn’t support threads
-no parallel execution
-whole process blocks if only one user thread blocks
-need to reimplement parts of the OS
one-to-one model
=> Kernel level threads
kernel knows and manages every thread, every thread known by kernel maps to one thread known by user
+real parallelism possible
+threads block individually
-OS manages every thread in the system
-Syscalls needed for thread management
-scheduling fixed in OS
Explain two types of threads
Kernel-level threads: The TCB is implemented in the OS kernel. The kernel is thus fully aware of the threads and responsible for managing them
User-level threads: The thread is fully implemented in a user-space program or library. The kernel is not aware of the threads.
What are the disadvantages of many to one thread model
- blocking system calls block the entire application
- can’t benefit from multiple CPUs/ cores
- high implementation work
explain hybrid thread model
m-to-n model: m user-level threads are mapped to n kernel-level threads. The hybrid thread model combines the flexibility of a user-space thread library with the benefits of kernel-level threads (true parallelism, individual thread blocking).
Why does a switch to a thread of a different process normally take longer than a switch to a thread in the same process?
When switching to a thread in a different process, the OS needs to perform a full context switch, which includes switching to a different PCB and address space. The most state can remain the same for a thread switch in the same process. The current kernel stack and register state needs to be exchanged.
Name structures in memory and an operation that the kernel needs to allocate until the CPU executes a newly created kernel-level thread
Data Structures:
- Create a new thread control block (in kernel space)
- allocate a stack (user memory)
- allocate a kernel stack (kernel memory)
Operations:
- add the new thread to the (process’s) list of threads
- perform a context switch to the new thread
Actions taken by the kernel to perform context-switch between processes
-> preserve the previous execution state (context) on the stack and in that process’ PCB
-> exchange stack pointers
-> load new state from the new stack and PCB
Explain the terms process, address space and thread. How do they relate to each other?
A thread is an independent entity of execution, representing control flow. A thread resides within an address space. The combination of a thread and its address space is a single-threaded process.
Which events can trigger one-to-one thread switch
voluntary:
- callling yield()
- executing a blocking syscall (like read())
involuntary:
- preemption, for example due to end of time slice, high priority thread becoming ready, device interrupt, exception that can’t be handled immediately etc.
Which events can trigger a many-to-one thread switch
a m-to-n thread is never preempted but must call ult_yield() from time to time to allow other ULTs to make progess.