FINALS Flashcards
What are the two main parts of a process and what do they encapsulate?
Threads encapsulate concurrency (the active part), while address spaces encapsulate protection (the passive part).
What is the difference between a heavyweight process and a lightweight process?
A heavyweight process is a process with its own resources, a lightweight process is a thread with shared resources within the same process.
What is a context switch and how does it relate to process multiplexing?
A context switch involves saving the state of the currently running process and loading the state of a new process. This is essential for process multiplexing, which allows multiple processes to share CPU time.
Explain the concept of an execution stack and its significance in thread execution.
The execution stack is a data structure that stores temporary results, parameters, and return addresses during function calls. It enables recursive execution and is crucial for modern programming languages.
Describe the purpose and functionality of the ThreadFork() operation in multithreaded programming.
ThreadFork() creates a new thread to execute a specific function with given arguments, enabling concurrent task execution.
How does the operating system use a timer interrupt for fair scheduling among threads?
The timer interrupt periodically forces a context switch, allowing the OS to schedule other threads and prevent monopolization of the CPU.
What are the advantages and disadvantages of using threads compared to processes?
Threads are lightweight and require less overhead than processes. However, threads share the same address space, which can cause synchronization issues.
Differentiate between internal and external events that can cause a thread to yield control.
Internal events occur within the thread, such as I/O blocking. External events, like timer interrupts, originate outside the thread.
How does Simultaneous Multithreading (SMT)/Hyperthreading enhance CPU performance?
SMT/Hyperthreading creates virtual cores by duplicating the register state, allowing multiple threads to execute concurrently on one core, improving efficiency.
What is a working set, and how does it impact context switching overhead?
The working set is the actively used memory of a process. Larger working sets increase context switching overhead as more data must be saved and restored.
Describe the five states in the lifecycle of a process.
New: The process is being created.
Ready: Waiting to run.
Running: Executing instructions.
Waiting: Paused for an event.
Terminated: Finished execution.
main() {
ThreadFork(ComputePI, “pi.txt” ));
ThreadFork(PrintClassList, “classlist.txt”));
}
What is the purpose of the ThreadFork() function in the code snippet?
ThreadFork() starts a new thread to execute a specific function with provided arguments. For example, ThreadFork(ComputePI, “pi.txt”) creates a thread to execute ComputePI with “pi.txt”.
Explain the concept of an execution stack and its importance in programming.
The execution stack stores temporary data like function parameters, local variables, and return addresses. It enables recursive calls and scoped variables, essential for structured programming.
What are the steps involved in saving and restoring the CPU state during a context switch?
- Save the current thread’s state (PC, registers, stack pointer) to its TCB.
- Load the new thread’s state from its TCB into the CPU.
This ensures threads resume correctly from where they left off.
- Load the new thread’s state from its TCB into the CPU.
Why is saving and restoring the CPU state crucial during a context switch?
It maintains thread isolation and program correctness. Without it, data corruption and unpredictable behavior could occur.
What is the concept of a yield() operation in thread execution?
Yield() allows a thread to voluntarily relinquish the CPU, giving other threads a chance to execute, promoting fairness and responsiveness.
Glossary
Process
Independent execution unit with its own memory and resources.
Glossary
Thread
Lightweight execution unit within a process sharing resources.
Concurrency
Simultaneous execution of tasks for efficiency.
Thread Control Block (TCB)
Stores thread state and scheduling info.
Context Switch
Saves/restores thread states for CPU sharing.
Yield()
Voluntary relinquishment of CPU by a thread.
Interrupt
Signal interrupting normal execution for a specific task.
Timer Interrupt
Periodic interrupt for OS scheduling.