1Processes that are in progress over the same period of time are known as:
Concurrent processes
Easy
A.Concurrent processes
B.Child processes
C.Sequential processes
D.Idle processes
Correct Answer: Concurrent processes
Explanation:
Concurrent processes are defined as two or more processes whose execution overlaps in time. They don't have to be running at the exact same instant, but their lifetimes overlap.
Incorrect! Try again.
2A process is considered a 'co-operating process' if it can:
Co-operating processes
Easy
A.Run completely independent of all other processes
B.Affect or be affected by other executing processes
C.Only execute on a single-core CPU
D.Never share data with other processes
Correct Answer: Affect or be affected by other executing processes
Explanation:
Co-operating processes are those that can share data, messages, or other resources, allowing them to influence or be influenced by the execution of other processes.
Incorrect! Try again.
3A segment of code in which a process accesses shared variables and resources is called a(n):
Critical Section Problem
Easy
A.Critical Section
B.Remainder Section
C.Deadlock Section
D.Entry Section
Correct Answer: Critical Section
Explanation:
The critical section is the specific part of a program where shared resources are accessed. Access to this section must be synchronized to prevent data inconsistencies.
Incorrect! Try again.
4Which of the following is a fundamental requirement for any solution to the Critical Section Problem?
Critical Section Problem
Easy
A.Starvation
B.Mutual Exclusion
C.Deadlock
D.Race Condition
Correct Answer: Mutual Exclusion
Explanation:
Mutual exclusion is the property that ensures if one process is executing in its critical section, no other processes can be executing in their critical sections for the same shared resource.
Incorrect! Try again.
5In the context of operating systems, a semaphore is essentially a(n):
Semaphores
Easy
A.File pointer
B.Hardware interrupt
C.Integer variable
D.CPU register
Correct Answer: Integer variable
Explanation:
A semaphore is a synchronization tool that acts as a protected integer variable. It is used to control access to a shared resource by multiple processes.
Incorrect! Try again.
6The two primary atomic operations performed on a semaphore are wait() and ____.
Semaphores
Easy
A.run()
B.check()
C.signal()
D.stop()
Correct Answer: signal()
Explanation:
The wait() operation (or P) decrements the semaphore value, and the signal() operation (or V) increments it. These are the fundamental, indivisible operations used for synchronization.
Incorrect! Try again.
7The Producer-Consumer problem is a classic example of a(n):
Producer consumer problem
Easy
A.Synchronization problem
B.Memory fragmentation problem
C.File system management problem
D.CPU scheduling problem
Correct Answer: Synchronization problem
Explanation:
The Producer-Consumer problem, also known as the bounded-buffer problem, is a canonical example used to illustrate issues and solutions related to process synchronization.
Incorrect! Try again.
8In the Producer-Consumer problem, what is the primary role of the 'producer' process?
Producer consumer problem
Easy
A.To generate data and place it into a shared buffer
B.To delete the shared buffer when it is empty
C.To remove data from a shared buffer
D.To determine the size of the shared buffer
Correct Answer: To generate data and place it into a shared buffer
Explanation:
The producer's function is to create items (data) and add them to the shared buffer, which acts as a queue for the consumer process.
Incorrect! Try again.
9In the classic Reader-Writer problem, which of the following scenarios is allowed?
Reader-writer Problem
Easy
A.A writer process accessing data while another writer is waiting
B.One writer process and one reader process accessing the data at the same time
C.Multiple reader processes accessing the shared data at the same time
D.Multiple writer processes accessing the shared data at the same time
Correct Answer: Multiple reader processes accessing the shared data at the same time
Explanation:
The main constraint of the problem is that multiple readers can read the data concurrently, but a writer must have exclusive access to prevent data corruption.
Incorrect! Try again.
10In the Dining Philosophers problem, what are the shared resources that the philosophers compete for?
Dining Philosopher Problem
Easy
A.The table
B.Chopsticks
C.Bowls of rice
D.Chairs
Correct Answer: Chopsticks
Explanation:
The problem models philosophers who need to acquire two chopsticks (one on their left and one on their right) to eat. The chopsticks represent the shared, limited resources.
Incorrect! Try again.
11What is the primary purpose of a Monitor as a synchronization tool?
Monitors
Easy
A.To directly manage CPU registers for faster context switching
B.To provide a high-level, easy-to-use mechanism for ensuring mutual exclusion
C.To allocate physical memory to processes
D.To increase the priority of I/O bound processes
Correct Answer: To provide a high-level, easy-to-use mechanism for ensuring mutual exclusion
Explanation:
Monitors are an abstract data type that encapsulates shared data and the procedures that operate on it, simplifying synchronization by automatically enforcing mutual exclusion.
Incorrect! Try again.
12At any given moment, how many processes can be actively executing code inside a monitor?
Monitors
Easy
A.An unlimited number
B.Exactly two
C.Only one
D.As many as there are CPU cores
Correct Answer: Only one
Explanation:
A fundamental property of a monitor is that it ensures mutual exclusion. Therefore, only one process can be active within the monitor at any time.
Incorrect! Try again.
13Which of the following is a common hardware instruction used for implementing synchronization primitives?
hardware primitives for synchronization
Easy
A.read()
B.TestAndSet()
C.fork()
D.exec()
Correct Answer: TestAndSet()
Explanation:
The TestAndSet() instruction is an atomic (indivisible) hardware primitive that reads a value from memory and writes a new value in a single, uninterruptible operation, making it useful for building locks.
Incorrect! Try again.
14Peterson's Solution is a classic software-based solution for the critical section problem involving how many processes?
classical two process and n-process solutions
Easy
A.N processes
B.Only one process
C.Two processes
D.Three processes
Correct Answer: Two processes
Explanation:
Peterson's solution is a well-known algorithm that correctly solves the critical-section problem for exactly two concurrent processes using shared memory.
Incorrect! Try again.
15A thread is often referred to as a:
Threads: Overview
Easy
A.Kernel
B.Shell
C.Lightweight process
D.Heavyweight process
Correct Answer: Lightweight process
Explanation:
Threads are called lightweight processes because they share the same address space and resources of their parent process, making them less resource-intensive to create and manage than separate processes.
Incorrect! Try again.
16What is a major advantage of using threads compared to using multiple processes?
Threads: Overview
Easy
A.Threads are more secure and isolated from each other
B.Threads always execute faster than processes
C.A crash in one thread never affects other threads in the process
D.Threads within the same process share memory and resources
Correct Answer: Threads within the same process share memory and resources
Explanation:
Sharing resources like memory makes communication between threads much faster and more efficient than inter-process communication (IPC), which is a key benefit of multithreading.
Incorrect! Try again.
17In the 'one-to-one' multithreading model, each user-level thread is mapped to a unique:
Multithreading Models
Easy
A.CPU core
B.Kernel thread
C.Group of kernel threads
D.Process
Correct Answer: Kernel thread
Explanation:
The one-to-one model provides a direct mapping between a user thread and a kernel thread. This allows for better concurrency, as a blocking call by one thread does not block others.
Incorrect! Try again.
18A significant disadvantage of the 'many-to-one' multithreading model is that:
Multithreading Models
Easy
A.A blocking system call by one thread will block the entire process
B.It is very expensive to create new user threads
C.It requires special hardware support
D.It cannot be implemented on single-processor systems
Correct Answer: A blocking system call by one thread will block the entire process
Explanation:
Since all user-level threads are mapped to a single kernel thread, if one user thread makes a blocking call, the kernel blocks that single kernel thread, effectively pausing all other user threads in that process.
Incorrect! Try again.
19In a precedence graph, a directed edge from process to signifies that:
Precedence graph
Easy
A.A statement in must be executed before a statement in
B. is the parent process of
C.A statement in must be executed before a statement in
D. and can be executed concurrently
Correct Answer: A statement in must be executed before a statement in
Explanation:
A precedence graph shows the execution order dependencies between processes or statements. An edge from to means must complete before can begin.
Incorrect! Try again.
20In a system with a process hierarchy, when a process creates a new process, the original process is called the:
Hierarchy of processes
Easy
A.Parent process
B.Zombie process
C.Orphan process
D.Child process
Correct Answer: Parent process
Explanation:
The process that performs the act of creation is termed the 'parent process,' and the newly created process is its 'child process,' forming a hierarchical relationship.
Incorrect! Try again.
21A shared variable count is initialized to 0. A counting semaphore S is initialized to 1. Two processes, P1 and P2, concurrently execute the code below. P1 executes its loop 5 times, and P2 executes its loop 3 times. What is the final value of count?
P1 Code:
c
for (i = 0; i < 5; i++) {
wait(S);
count++;
signal(S);
}
P2 Code:
c
for (j = 0; j < 3; j++) {
wait(S);
count++;
signal(S);
}
Semaphores
Medium
A.The value can be anything between 3 and 8.
B.The final value is non-deterministic and cannot be predicted.
C.The value is always 8.
D.The value is always 5.
Correct Answer: The value is always 8.
Explanation:
The semaphore S is used as a mutex (initialized to 1), ensuring that the operation count++ is atomic. This prevents race conditions. Since P1 increments the count 5 times and P2 increments it 3 times, and these increments are serialized by the mutex, the final value will be the sum of the increments, which is 0 + 5 + 3 = 8, regardless of the interleaving of the processes.
Incorrect! Try again.
22Peterson's solution to the critical section problem requires two shared variables: int turn; and boolean flag[2];. Which of these statements accurately describes why both are necessary?
Critical Section Problem
Medium
A.turn indicates which process has priority, while flag is used for deadlock prevention.
B.flag indicates a process's intent to enter the critical section, while turn resolves conflicts when both processes want to enter simultaneously.
C.flag ensures bounded waiting, while turn ensures mutual exclusion.
D.turn handles mutual exclusion, while flag handles progress.
Correct Answer: flag indicates a process's intent to enter the critical section, while turn resolves conflicts when both processes want to enter simultaneously.
Explanation:
In Peterson's solution, flag[i] = true signals that process i is ready to enter its critical section. The while (flag[j] && turn == j); loop checks the other process. If both processes set their flags to true at the same time, the turn variable acts as a tie-breaker, allowing only one process to proceed, thus ensuring mutual exclusion while also guaranteeing progress and bounded waiting.
Incorrect! Try again.
23What is the primary advantage of using a monitor for process synchronization over using semaphores directly?
Monitors
Medium
A.Monitors are more efficient and result in less overhead than semaphores.
B.Monitors allow for more concurrency than semaphores by allowing multiple processes in the critical section.
C.Semaphores cannot solve complex synchronization problems like the Reader-Writer problem, whereas monitors can.
D.Monitors encapsulate synchronization logic, making concurrent code simpler and less error-prone by ensuring mutual exclusion is handled automatically.
Correct Answer: Monitors encapsulate synchronization logic, making concurrent code simpler and less error-prone by ensuring mutual exclusion is handled automatically.
Explanation:
The key advantage of monitors is abstraction. They are a higher-level synchronization construct. Programmers don't need to explicitly code wait() and signal() calls to enforce mutual exclusion for the shared data. The compiler/runtime handles this, reducing the risk of common errors like forgetting to call signal(S) or calling wait(S) twice. Semaphores are more primitive and require careful management by the programmer.
Incorrect! Try again.
24A common deadlock-free solution to the Dining Philosophers problem involves allowing a philosopher to pick up their chopsticks only if both are available. This is an implementation of which deadlock prevention strategy?
Dining Philosopher Problem
Medium
A.Breaking the Hold and Wait condition.
B.Breaking the No Preemption condition.
C.Breaking the Mutual Exclusion condition.
D.Breaking the Circular Wait condition.
Correct Answer: Breaking the Hold and Wait condition.
Explanation:
The 'Hold and Wait' condition for deadlock occurs when a process holds at least one resource and is waiting to acquire additional resources held by other processes. By requiring a philosopher to pick up both chopsticks simultaneously (in an atomic operation), we ensure that they never hold one chopstick while waiting for the other. This directly prevents the 'Hold and Wait' condition from occurring.
Incorrect! Try again.
25In the first solution to the Reader-Writer problem (where readers have priority), which potential issue can arise?
Reader-writer Problem
Medium
A.Starvation of readers.
B.Deadlock between readers and writers.
C.Starvation of writers.
D.A race condition that allows two writers in the critical section simultaneously.
Correct Answer: Starvation of writers.
Explanation:
In a readers-priority solution, as long as at least one reader is active, new incoming readers are allowed to start reading. If there is a continuous stream of readers, a writer might wait indefinitely to acquire the lock, leading to writer starvation. The lock will never be released to a writer if readers keep arriving.
Incorrect! Try again.
26Consider a system using the many-to-one multithreading model. Why is this model not well-suited for a multi-core processor architecture?
Multithreading Models
Medium
A.It is complex for the kernel to manage.
B.Context switching between user threads is slow.
C.Creating user-level threads is a high-overhead operation.
D.It cannot take advantage of multiple cores since only one kernel thread can run at a time.
Correct Answer: It cannot take advantage of multiple cores since only one kernel thread can run at a time.
Explanation:
In the many-to-one model, all user-level threads of a process are mapped to a single kernel thread. Since the kernel schedules kernel threads, only one thread from that process can execute at any given moment, regardless of how many CPU cores are available. This prevents true parallelism for that process, making the model inefficient for multi-core systems.
Incorrect! Try again.
27The TestAndSet() hardware instruction is defined as follows. How does it primarily ensure mutual exclusion?
A.By requiring a while loop to repeatedly check the lock.
B.By setting the lock to TRUE after checking its value.
C.By being an atomic, non-interruptible operation.
D.By returning the initial value of the lock.
Correct Answer: By being an atomic, non-interruptible operation.
Explanation:
The key feature of TestAndSet() and other hardware primitives is atomicity. The entire operation of reading the target's value, setting the target to TRUE, and returning the old value is performed as a single, indivisible hardware instruction. This prevents any other process from interfering between the 'test' (reading *target) and the 'set' (writing to *target), which is essential for correctly implementing a lock.
Incorrect! Try again.
28In a bounded-buffer producer-consumer problem implemented with semaphores, what is the initial value of the semaphore full and what does it represent?
Producer consumer problem
Medium
A.full is initialized to 0 and represents the number of items in the buffer.
B.full is initialized to 0 and represents the number of empty slots in the buffer.
C.full is initialized to n (buffer size) and represents the number of empty slots in the buffer.
D.full is initialized to n (buffer size) and represents the number of items in the buffer.
Correct Answer: full is initialized to 0 and represents the number of items in the buffer.
Explanation:
The semaphore full tracks the number of slots in the buffer that are filled with items. Initially, the buffer is empty, so full is initialized to 0. The producer signal(full) after adding an item, and the consumer wait(full) before removing an item. Conversely, the semaphore empty is initialized to n and tracks the number of empty slots.
Incorrect! Try again.
29Consider the following set of statements with dependencies:
S1: a = 1;
S2: b = a + 2;
S3: c = 3;
S4: d = b + c;
S5: e = d + 1;
Which of the following represents a valid precedence relationship in the precedence graph for these statements?
Precedence graph
Medium
A.S5 can execute concurrently with S4.
B.S4 must execute before S2.
C.S1 and S3 can execute concurrently.
D.S3 must execute before S2.
Correct Answer: S1 and S3 can execute concurrently.
Explanation:
A precedence graph shows the execution dependencies. S2 depends on S1 (b needs a). S4 depends on S2 and S3 (d needs b and c). S5 depends on S4. There is no dependency between S1 (a=1) and S3 (c=3). Therefore, they can be executed in any order relative to each other, or concurrently, before S4 is executed.
Incorrect! Try again.
30Which multithreading model provides the best balance between concurrency and resource efficiency, and is adopted by modern operating systems like Linux, Windows, and Solaris?
Multithreading Models
Medium
A.One-to-One Model
B.Single-Threaded Model
C.Many-to-One Model
D.Many-to-Many Model (or Two-Level Model)
Correct Answer: Many-to-Many Model (or Two-Level Model)
Explanation:
The Many-to-Many model (often implemented as a Two-Level model) multiplexes many user-level threads to a smaller or equal number of kernel threads. This model overcomes the limitations of the other two: it allows for true parallelism (unlike many-to-one) and doesn't have the overhead of creating a kernel thread for every user thread (unlike one-to-one). It provides a good compromise, which is why it's the basis for threading libraries in most modern OSes.
Incorrect! Try again.
31Two processes, P1 and P2, share a memory segment. P1 writes a value to the segment, and P2 reads it. This interaction is an example of co-operating processes. What is the primary reason these processes need a synchronization mechanism?
Co-operating processes
Medium
A.To allow P1 and P2 to have the same process ID.
B.To increase the execution speed of both processes.
C.To prevent the OS from deallocating the shared memory.
D.To ensure P2 does not read the value before P1 has finished writing it.
Correct Answer: To ensure P2 does not read the value before P1 has finished writing it.
Explanation:
Co-operating processes can affect each other's execution. Without synchronization, a race condition can occur. P2 might read the shared memory while P1 is in the middle of writing to it, resulting in a partial or invalid value. Synchronization primitives (like semaphores or mutexes) are needed to enforce an order, ensuring that the read operation happens only after the write operation is complete.
Incorrect! Try again.
32Lamport's Bakery Algorithm for the n-process critical section problem has a key property that distinguishes it from many semaphore-based solutions. What is this property?
classical two process and n-process solutions
Medium
A.It guarantees that processes enter the critical section in a last-in, first-out (LIFO) order.
B.It does not require a shared variable to be read and written in a single atomic instruction.
C.It is immune to process failure inside the critical section.
D.It requires special hardware instructions.
Correct Answer: It does not require a shared variable to be read and written in a single atomic instruction.
Explanation:
The Bakery algorithm is significant because it solves the critical section problem for n processes using only shared memory that does not require atomic read-modify-write instructions like TestAndSet. While it assumes atomic reads and writes of primitive types (like integers), it does not need a more complex hardware-level atomic primitive. This makes it a pure software solution.
Incorrect! Try again.
33When a process creates a new thread, which of the following is typically NOT shared between the parent process's thread and the new thread?
Threads: Overview
Medium
A.The stack
B.The file descriptors
C.The heap memory
D.The global variables
Correct Answer: The stack
Explanation:
Threads within the same process share most of their resources, including the code segment, data segment (global variables), heap, and operating system resources like open files. However, each thread must have its own separate stack to manage its local variables, function calls, and execution state. This is fundamental to allowing threads to execute independently.
Incorrect! Try again.
34A process executes wait(S) on a counting semaphore S whose current value is -2. What happens to the process?
Semaphores
Medium
A.The process continues execution and the value of S becomes -3.
B.The process continues execution, but the value of S remains -2.
C.The process is blocked and placed in the semaphore's wait queue, and the value of S becomes -3.
D.It causes a runtime error, as semaphore values cannot be negative.
Correct Answer: The process is blocked and placed in the semaphore's wait queue, and the value of S becomes -3.
Explanation:
In a common implementation of counting semaphores, the integer value represents the number of available resources. If the value is negative, its magnitude (|-2| = 2) represents the number of processes waiting for the resource. When a new process executes wait(S), it first decrements S (from -2 to -3) and then, because the result is negative, it blocks and is added to the wait queue. There are now 3 processes waiting.
Incorrect! Try again.
35Inside a monitor, a process calls x.wait(). What is the state of the monitor lock at this point?
Monitors
Medium
A.The monitor lock is released, allowing another process to enter the monitor.
B.The monitor lock is passed to the next process in the condition variable's queue.
C.The system deadlocks because a process cannot wait inside a monitor.
D.The process continues to hold the monitor lock while it is waiting.
Correct Answer: The monitor lock is released, allowing another process to enter the monitor.
Explanation:
When a process within a monitor calls wait() on a condition variable, it does two things: 1) it suspends its own execution and is placed in the condition variable's wait queue, and 2) it releases the mutual exclusion lock on the monitor. This is crucial because it allows another process to enter the monitor, potentially change the state, and signal the waiting process to continue.
Incorrect! Try again.
36How does the CompareAndSwap(int *value, int expected, int new_value) instruction provide a more powerful synchronization mechanism than TestAndSet()?
hardware primitives for synchronization
Medium
A.It allows for general, non-binary updates to a shared variable in one atomic step, preventing the lost update problem.
B.It avoids the busy-waiting problem that TestAndSet causes.
C.It solves the ABA problem by preventing a value from being changed.
D.It is faster because it doesn't need to return a value.
Correct Answer: It allows for general, non-binary updates to a shared variable in one atomic step, preventing the lost update problem.
Explanation:
TestAndSet can only set a value to TRUE. CompareAndSwap (CAS) is more general. It checks if the current *value is equal to an expected value. Only if they match does it update *value to new_value. This atomic 'check-then-update' operation can be used to implement not just locks, but also lock-free data structures (like atomic counters or linked-list insertions) by ensuring an update only happens if the state hasn't changed since it was last read.
Incorrect! Try again.
37What is the primary goal of using scheduler activations as a communication mechanism between the kernel and the user-level thread library?
scheduler activations
Medium
A.To maintain the one-to-one mapping between user and kernel threads.
B.To eliminate the need for kernel threads entirely.
C.To allow user threads to directly schedule themselves on the CPU core.
D.To inform the user-level scheduler about kernel events (like blocking I/O) so it can make better scheduling decisions.
Correct Answer: To inform the user-level scheduler about kernel events (like blocking I/O) so it can make better scheduling decisions.
Explanation:
Scheduler activations act as a bridge for the many-to-many model. When a kernel thread is about to block (e.g., on I/O), the kernel makes an 'upcall' to the user-level thread library via a scheduler activation. This upcall informs the library that a kernel thread is no longer available. The library can then schedule another runnable user thread onto a different available activation (kernel thread), thus preventing the entire process from blocking and maintaining concurrency.
Incorrect! Try again.
38In a UNIX-like operating system, a process creates a child process using fork(). If the parent process terminates before the child process, and the child continues to run, what does the child process become?
Hierarchy of processes
Medium
A.A session leader
B.A zombie process
C.A daemon process
D.An orphan process
Correct Answer: An orphan process
Explanation:
An orphan process is a running process whose parent has terminated. In UNIX-like systems, such processes are 'adopted' by a special system process, typically init (process ID 1), which then becomes their new parent. This ensures the process doesn't remain in the system without a parent to eventually collect its exit status.
Incorrect! Try again.
39Which of the following statements best distinguishes concurrent execution from parallel execution?
Concurrent processes
Medium
A.Concurrency is when multiple tasks are making progress over time by interleaving, while parallelism is when multiple tasks are executing simultaneously.
B.There is no difference; the terms are interchangeable.
C.Parallelism is a software concept, while concurrency is a hardware concept.
D.Concurrency is only possible on multi-core systems, while parallelism is possible on single-core systems.
Correct Answer: Concurrency is when multiple tasks are making progress over time by interleaving, while parallelism is when multiple tasks are executing simultaneously.
Explanation:
This is a key distinction. Concurrency is a logical concept about the structure of a program dealing with multiple tasks at once. It can be implemented on a single CPU core via time-slicing (interleaving). Parallelism is a physical concept where multiple tasks are literally running at the same instant in time, which requires multiple processing units (e.g., CPU cores).
Incorrect! Try again.
40A modern web server often uses a multithreaded architecture where a master thread listens for requests and dispatches each new connection to a worker thread. What is the primary advantage of this model over a single-threaded, iterative server?
examples of threaded programs
Medium
A.It guarantees that requests are served in the exact order they are received.
B.It uses less memory because threads are lightweight.
C.It simplifies the code by removing the need for a listening socket.
D.It prevents the server from blocking while waiting for a slow client, allowing it to serve other clients concurrently.
Correct Answer: It prevents the server from blocking while waiting for a slow client, allowing it to serve other clients concurrently.
Explanation:
In a single-threaded iterative server, if one client connection involves a long-running task (like a large file download or slow network), the entire server is blocked and cannot accept new connections or service other clients. By dispatching each connection to a separate worker thread, the master thread can immediately go back to listening for new connections. This allows the server to handle many clients concurrently, significantly improving throughput and responsiveness.
Incorrect! Try again.
41Two processes, P1 and P2, share a counting semaphore S initialized to 1 and a variable x initialized to 0. The code for the processes is as follows:
If P2 starts first and is preempted immediately after executing x=x*2, then P1 runs to completion, and finally P2 resumes and runs to completion, what is the final value of x?
Semaphores
Hard
A.5
B.6
C.-1
D.4
Correct Answer: 4
Explanation:
Initial State:S = 1, x = 0.
P2 starts: Executes signal(S). State becomes S = 2, x = 0.
P2 continues: Executes x = x * 2. State remains S = 2, x = 0 * 2 = 0.
P2 is preempted. Current state: S = 2, x = 0.
P1 runs to completion:
wait(S): S becomes 1. (S > 0, no block).
x = x + 1: x becomes 1.
wait(S): S becomes 0. (S > 0, no block).
x = x + 5: x becomes 6.
signal(S): S becomes 1.
P1 completes. Current state: S = 1, x = 6.
P2 resumes:
signal(S): S becomes 2.
x = x - 2: x becomes 6 - 2 = 4.
wait(S): S becomes 1. (S > 0, no block).
P2 completes. Final state: x = 4.
Incorrect! Try again.
42In a monitor implementation using Mesa semantics, a thread T1 is waiting on a condition variable cond. Another thread T2 executes cond.signal() and then continues to modify the shared state within the monitor before finally exiting. When thread T1 is eventually rescheduled and acquires the monitor lock, what is the most critical action it must perform immediately upon waking?
Monitors
Hard
A.Release the monitor lock to allow other threads to proceed.
B.Assume the condition is now true and proceed.
C.Re-evaluate the condition it was waiting for in a loop.
D.Immediately signal another waiting thread to prevent starvation.
Correct Answer: Re-evaluate the condition it was waiting for in a loop.
Explanation:
Under Mesa semantics, signal() moves a waiting thread from the condition queue to the ready queue for the monitor lock, but the signaling thread (T2) retains the lock and continues execution. By the time the waiting thread (T1) reacquires the lock, the state may have been changed by T2 or even another thread that entered the monitor in the interim. Therefore, T1 cannot assume the condition is true. It must re-check the condition, which is why condition waits in Mesa-style monitors are always enclosed in a while loop (e.g., while(!condition) cond.wait();).
Incorrect! Try again.
43A deadlock-free solution to the Dining Philosophers problem with philosophers is implemented where each philosopher must acquire both forks simultaneously via a single atomic operation within a critical section. If the operation fails (because one or both forks are unavailable), the philosopher waits. This prevents deadlock. However, which concurrency problem is still a significant risk in this specific implementation?
Dining Philosopher Problem
Hard
A.Livelock
B.Circular wait
C.Starvation
D.Violation of mutual exclusion
Correct Answer: Starvation
Explanation:
This solution correctly prevents deadlock because a philosopher never holds one fork while waiting for another, thus breaking the circular wait condition. Mutual exclusion is maintained. Livelock is not the primary issue. However, starvation is still possible. Consider a scenario where philosopher P2 and P4 are alternatingly eating. Their neighbor, P3, will always find one of its required forks busy whenever it tries to pick them up. If the scheduler consistently favors P2 and P4 over P3, P3 can wait indefinitely (starve) without ever getting a chance to eat.
Incorrect! Try again.
44You are implementing a lock-free stack using an atomic CompareAndSwap(CAS) operation. The pop operation is implemented as follows:
c
loop {
top_ptr = head.load();
if (top_ptr == null) return null;
next_ptr = top_ptr->next.load();
} until (CAS(&head, top_ptr, next_ptr));
return top_ptr->data;
Another thread performs a rapid sequence of operations: push(A), push(B), pop() (returns B), pop() (returns A), then push(B) again, where the newly pushed B happens to be allocated at the same memory address as the original B. What problem can cause the first pop thread to fail catastrophically if it was preempted after reading the original head?
hardware primitives for synchronization
Hard
A.The lost update problem
B.A deadlock due to CAS failure
C.The ABA problem
D.Instruction reordering by the CPU
Correct Answer: The ABA problem
Explanation:
This scenario describes the classic ABA problem.
Thread T1 reads head which points to node B (value A). Let's say its address is 0x100. T1 is preempted.
Another thread pops B, pops A, then pushes a new node B' (value A again). B' might be allocated at the same address 0x100.
T1 resumes. Its CAS operation compares the current head (0x100) with its old value (0x100). The comparison succeeds.
T1 then incorrectly swings the head pointer to its stored next_ptr, which pointed to the original A, corrupting the stack. The CAS succeeds because the values (addresses) are the same (A -> A), but the underlying state they represent has changed (B -> B').
Incorrect! Try again.
45In a reader-writer solution that gives strong preference to writers, a writer W1 is waiting for the current reader R1 to finish. While W1 is waiting, a stream of new readers (R2, R3) and writers (W2, W3) arrive. According to a typical writer-preference algorithm, what is the guaranteed order of execution after R1 finishes?
Reader-writer Problem
Hard
A.W1, W2, W3 will execute before R2, R3.
B.W1 will execute, followed by all waiting readers (R2, R3), then the remaining writers.
C.All waiting writers (W1, W2, W3) and readers (R2, R3) will compete, and the winner is non-deterministic.
D.W1 will execute, then R2, R3, W2, W3 will compete.
Correct Answer: W1, W2, W3 will execute before R2, R3.
Explanation:
Writer-preference solutions are designed to prevent writers from being starved by a continuous stream of readers. When a writer (W1) is waiting, any newly arriving readers (R2, R3) are blocked. Any newly arriving writers (W2, W3) are queued up. Once the current read operation (R1) is complete, the lock is passed to the waiting writers. The algorithm will ensure that all writers who were waiting when the lock became free are serviced before any of the waiting readers get a chance. Therefore, W1, W2, and W3 will all execute before R2 and R3.
Incorrect! Try again.
46A process on a system uses a many-to-many threading model, mapping user-level threads to kernel-level threads, where . If exactly of the user-level threads execute blocking system calls simultaneously, what is the most precise implication for the remaining user-level threads?
Multithreading Models
Hard
A.The remaining threads continue to be scheduled by the user-level scheduler, sharing the remaining processor time.
B.The operating system migrates the process to a different CPU core with available kernel threads.
C.The kernel automatically creates new kernel threads to service the remaining user threads.
D.The remaining threads are unable to run on a CPU until at least one of the blocking calls completes.
Correct Answer: The remaining threads are unable to run on a CPU until at least one of the blocking calls completes.
Explanation:
In the many-to-many model, user-level threads need a kernel-level thread to execute on the CPU. When a user thread makes a blocking system call, the kernel thread it is mapped to also blocks in the kernel. If all available kernel threads for that process become blocked, the remaining user-level threads have no available kernel threads to run on. Even if they are ready to run and the user-level scheduler picks one, there is no underlying execution context in the kernel, so they are effectively stalled.
Incorrect! Try again.
47Scheduler activations are a sophisticated mechanism to implement user-level threads. What is the primary function of the kernel's upcall to the user-level thread library when an event like a blocking I/O call occurs?
scheduler activations
Hard
A.To transfer the entire process's memory space to a new kernel thread.
B.To notify the user-level scheduler that a kernel thread is now blocked, allowing it to schedule another user thread on the activation.
C.To bypass the kernel for all future system calls made by that user thread.
D.To terminate the user thread that made the blocking call and report an error.
Correct Answer: To notify the user-level scheduler that a kernel thread is now blocked, allowing it to schedule another user thread on the activation.
Explanation:
The core innovation of scheduler activations is the bidirectional communication between the kernel and the user-level thread library. A standard kernel provides no information to the user-level scheduler about blocking events. An upcall is a message from the kernel up to the user-level library. It informs the library about an event, such as 'the user thread you were running on kernel thread K just blocked on I/O'. This notification allows the user-level scheduler to intelligently save the context of the blocked thread and schedule a different, ready-to-run user thread onto the now-available execution context (the activation).
Incorrect! Try again.
48Consider four processes and four semaphores, S1, S2, S3, S4, all initialized to 0. P1:...; signal(S1); signal(S3); P2:...; wait(S1); signal(S2); P3:...; wait(S2); wait(S4); ... P4:...; wait(S3); signal(S4);
Which precedence relationship is enforced by this synchronization scheme?
Precedence graph
Hard
A.P2's signal(S2) must happen before P4's signal(S4).
B.P3 can only run after P2 and P4 have both completed specific signaling actions.
C.P1 must complete before P2, P3, or P4 can begin.
D.P2 and P4 can run concurrently without any ordering constraints between them.
Correct Answer: P3 can only run after P2 and P4 have both completed specific signaling actions.
Explanation:
Let's trace the dependencies:
P1 signals S1 and S3. This allows P2 (waiting on S1) and P4 (waiting on S3) to start.
P2 must wait for P1 (wait(S1)). After it runs, it signals S2.
P4 must wait for P1 (wait(S3)). After it runs, it signals S4.
P3 must wait for both S2 and S4 (wait(S2); wait(S4);).
This means P3 cannot proceed until P2 has signaled S2 AND P4 has signaled S4. This creates a 'join' point where P3's execution is dependent on prior actions from both P2 and P4.
Incorrect! Try again.
49In a bounded-buffer problem with a buffer of size , three semaphores mutex=1, empty=N, full=0 are used. A producer has the following flawed code structure:
c
wait(mutex);
wait(empty);
// add item to buffer
signal(full);
signal(mutex);
Under what specific condition will this code lead to a system-wide deadlock?
Producer consumer problem
Hard
A.When two producers attempt to add items simultaneously.
B.When a producer tries to add an item to a full buffer.
C.When a consumer tries to take an item from an empty buffer.
D.When multiple consumers and producers are running and context switches happen frequently.
Correct Answer: When a producer tries to add an item to a full buffer.
Explanation:
The flaw is the order of wait(mutex) and wait(empty). Here's the deadlock scenario:
The buffer is full. empty semaphore is 0.
The producer process runs. It executes wait(mutex), successfully acquiring the lock on the buffer. mutex is now 0.
It then executes wait(empty). Since the buffer is full, empty is 0, and the producer process blocks.
Crucially, the producer is now blocked while still holding the mutex lock.
No consumer can enter its critical section to remove an item from the buffer because it will block on wait(mutex).
The producer is waiting for a consumer to signal empty, but no consumer can run to do so. This is a classic deadlock.
Incorrect! Try again.
50Lamport's Bakery Algorithm provides a solution to the n-process critical section problem. A key part of the algorithm involves each process checking two conditions for every other process before entering the critical section: while (choosing[j]) and while ((number[j] != 0) && ((number[j], j) < (number[i], i))). What is the primary purpose of the first check, while (choosing[j])?
classical two process and n-process solutions
Hard
A.To ensure strict First-In-First-Out (FIFO) ordering among all processes.
B.To resolve a race condition where is in the process of picking a ticket number which might be smaller than 's.
C.To satisfy the bounded waiting condition by giving priority to processes that have been waiting longer.
D.To prevent two processes, and , from picking the exact same ticket number.
Correct Answer: To resolve a race condition where is in the process of picking a ticket number which might be smaller than 's.
Explanation:
The process of picking a ticket number is not atomic. A process first sets choosing[i] = true, then calculates its number, and finally sets choosing[i] = false. If were to read number[j] while is in this critical phase, it might read an old (or zero) value for number[j] and incorrectly assume it has priority. The while (choosing[j]) loop forces to wait until has finished picking and writing its new ticket number, ensuring that makes its decision based on up-to-date information, thus preventing a violation of mutual exclusion.
Incorrect! Try again.
51A system's counting semaphore S is observed to have a value of -4. What is the most precise interpretation of this state?
Semaphores
Hard
A.No processes are blocked, and the next four wait(S) operations will not block.
B.The semaphore is in an illegal state, as its value cannot be negative.
C.The semaphore has had four more signal operations than wait operations.
D.Four processes are currently blocked in a queue waiting on semaphore S.
Correct Answer: Four processes are currently blocked in a queue waiting on semaphore S.
Explanation:
In many common implementations of counting semaphores, the integer value has a specific meaning. If the value is positive, it represents the number of available resources or signal calls that can be absorbed by wait calls without blocking. If the value is zero, no resources are available. If the value is negative, its absolute value represents the number of processes that are currently blocked on that semaphore's wait queue. Therefore, a value of -4 means exactly four processes are blocked, waiting for signal(S) to be called.
Incorrect! Try again.
52On a single-core (uniprocessor) system running an OS with a non-preemptive scheduler, how does the nature of the critical section problem change for user-level processes?
Critical Section Problem
Hard
A.The system is immune to deadlock but highly susceptible to livelock.
B.The critical section problem is entirely eliminated, as no two pieces of code can ever execute concurrently.
C.Software solutions like Peterson's algorithm are still required because logical race conditions can occur.
D.Mutual exclusion between user-level processes is guaranteed by the scheduler, but race conditions involving interrupt service routines are still possible.
Correct Answer: Mutual exclusion between user-level processes is guaranteed by the scheduler, but race conditions involving interrupt service routines are still possible.
Explanation:
In a non-preemptive uniprocessor system, a process runs until it voluntarily yields the CPU (e.g., for I/O) or terminates. It cannot be forcibly interrupted by the scheduler to run another user process. Therefore, if a process enters its critical section, it is guaranteed to finish it without another user process interfering. However, hardware interrupts can still occur at any time. If an interrupt service routine (ISR) accesses the same shared data as the user process, a race condition can still exist between the process and the ISR. So, mutual exclusion is solved at the process level but not globally.
Incorrect! Try again.
53A parent process on a UNIX-like system creates a child using fork(). The parent then opens a file, receiving file descriptor fd=5. Subsequently, the child, executing its own code, opens a completely different file and also happens to receive file descriptor fd=5. What is the outcome if the parent now writes to its fd=5?
Hierarchy of processes
Hard
A.The write is redirected to the file opened by the child process.
B.The write fails with an error because the child's fd=5 is now the active one.
C.The behavior is undefined, as the kernel is in an inconsistent state.
D.The write succeeds and data goes to the file originally opened by the parent.
Correct Answer: The write succeeds and data goes to the file originally opened by the parent.
Explanation:
This question tests the understanding that file descriptors are private to each process. Each process has its own file descriptor table. The integer 5 is just an index into this table. The parent's fd=5 points to a kernel file table entry for its file. The child's fd=5 points to a completely different kernel file table entry for its file. The two are independent. The child's actions (opening, using, or closing its fd=5) have no effect on the parent's fd=5. Therefore, the parent's write operation proceeds as normal.
Incorrect! Try again.
54A monitor is implemented under Hoare semantics (signal-and-urgent-wait). What is a potential major inefficiency or problem if a signaling process does not immediately exit the monitor after a cond.signal() call, but instead continues to perform more computations on the shared monitor state?
Monitors
Hard
A.It will cause a deadlock because the signaled process immediately gets the lock.
B.It violates the mutual exclusion property of the monitor.
C.It causes two context switches (signaler -> waiter, waiter -> signaler) instead of one.
D.It may alter the state such that the condition for which the waiting process was awakened is no longer true when it eventually runs.
Correct Answer: It causes two context switches (signaler -> waiter, waiter -> signaler) instead of one.
Explanation:
Under Hoare semantics, cond.signal() immediately transfers the monitor lock and CPU control to a waiting thread. The signaling thread is suspended. When the awakened thread finishes its work and exits the monitor (or waits again), it must return the lock and control back to the original signaling thread so it can continue its work. This results in two context switches. A common optimization pattern (signal-and-exit) is for the signaler to perform the signal as its very last action, which allows the awakened thread to proceed without needing to switch back to the now-finished signaler, saving a context switch.
Incorrect! Try again.
55The 'Test-and-Test-and-Set' (TTAS) spinlock is an optimization over a simple TestAndSet (TAS) spinlock. What is the primary source of this optimization's performance gain on modern, cache-coherent multi-core systems?
hardware primitives for synchronization
Hard
A.It consumes less power by putting the CPU into a low-power state during the spin.
B.It reduces interconnect bus traffic by spinning on a locally cached, read-only copy of the lock until it is released.
C.It guarantees fairness and prevents starvation, which a simple TAS lock does not.
D.It uses fewer CPU instructions to acquire the lock.
Correct Answer: It reduces interconnect bus traffic by spinning on a locally cached, read-only copy of the lock until it is released.
Explanation:
A simple TestAndSet lock continuously performs an atomic write operation. In a cache-coherent system, each write attempt invalidates the cache line holding the lock in all other cores' caches, causing a storm of traffic on the bus. TTAS improves this by first spinning in a tight loop that only reads the lock's value (the first 'Test'). A read can be satisfied by a local cache copy without generating bus traffic. Only when the read shows the lock is free does the process attempt the expensive atomic TestAndSet write operation. This drastically reduces bus contention.
Incorrect! Try again.
56When designing a high-performance server application, what is a primary motivation for using a thread pool instead of creating a new thread for each incoming request?
examples of threaded programs
Hard
A.To bypass the operating system's thread scheduler for better performance.
B.To ensure that all requests are processed in a strict first-in, first-out order.
C.To allow the application to run on systems that do not support kernel-level threads.
D.To amortize the high overhead of thread creation and destruction over many requests.
Correct Answer: To amortize the high overhead of thread creation and destruction over many requests.
Explanation:
Creating and destroying threads, especially kernel-level threads, are expensive operations. They involve significant overhead in allocating kernel memory (for the stack and TCB), interacting with the scheduler, and cleanup. For a server handling many short-lived requests, this overhead can become the main performance bottleneck. A thread pool pre-allocates a fixed number of worker threads. When a request arrives, it is dispatched to an idle thread from the pool. When the request is complete, the thread is returned to the pool, ready for the next request. This re-use of threads amortizes the creation cost, leading to much better throughput and lower latency.
Incorrect! Try again.
57Three processes P1, P2, and P3 are synchronized using three binary semaphores S0, S1, and S2, all initialized to 0. An external event signals S0 exactly once to start the system. The code is:
A.The system prints "C" exactly once, then continues printing a sequence of "A"s and "B"s while P3 remains permanently blocked.
B.The system prints the sequence "ABC" repeatedly.
C.The system prints an arbitrary interleaving of "A", "B", and "C" indefinitely.
D.The system deadlocks immediately after printing "A".
Correct Answer: The system prints "C" exactly once, then continues printing a sequence of "A"s and "B"s while P3 remains permanently blocked.
Explanation:
signal(S0) starts the system. P1 runs, prints "A", and signals S1 and S2.
P2 and P3 are now unblocked. They can run in any order.
P2 runs, waits on S1, prints "B", and then signals S0. This allows P1 to run again, creating an 'AB' cycle.
P3 runs, waits on S2, and prints "C". After printing, it loops back and immediately waits on S2 again.
The crucial flaw is that no process ever signals S2 a second time. P1 signals it once at the beginning. After P3 consumes that signal, S2 will remain 0 forever. Therefore, P3 will print "C" once and then block permanently on its second wait(S2) call. The P1-P2 interaction can continue, producing a sequence of 'A's and 'B's.
Incorrect! Try again.
58Two processes, P1 and P2, use strict alternation with a shared variable turn to access a critical section. P1 can only enter if turn == 1, and after exiting it sets turn = 2. P2 can only enter if turn == 2, and after exiting it sets turn = 1. This solution provides mutual exclusion. However, it violates the Progress requirement. Why?
Co-operating processes
Hard
A.The turn variable is not protected by a lock, creating a race condition.
B.If P1 wants to enter the critical section but P2 is in its remainder section (not interested in entering), P1 is still blocked.
C.If P1 is much faster than P2, it can enter the critical section multiple times before P2 gets a turn.
D.A deadlock occurs if both processes try to enter the critical section at the same time.
Correct Answer: If P1 wants to enter the critical section but P2 is in its remainder section (not interested in entering), P1 is still blocked.
Explanation:
The 'Progress' principle states that if no process is in its critical section and some processes wish to enter, the selection of the next process cannot be postponed indefinitely. In this strict alternation scheme, the processes are tightly coupled. If turn is 2, P1 is blocked, waiting for P2 to run, enter its critical section, and set turn to 1. If process P2 is currently in its non-critical remainder section and has no desire to enter its critical section, P1 is blocked unnecessarily. The decision to let P1 proceed is dependent on the unrelated activity of P2, which violates progress.
Incorrect! Try again.
59In the monitor-based solution to the Dining Philosophers problem (using state array and condition variables), the putdown(i) function, called when philosopher i finishes eating, is responsible for calling test((i-1)%N) and test((i+1)%N). What is the fundamental reason for this design?
Dining Philosopher Problem
Hard
A.To wake up a potentially waiting neighbor whose ability to eat was dependent on philosopher i's forks being available.
B.To ensure philosopher i does not immediately re-acquire the forks and starve its neighbors.
C.To check for a potential deadlock condition that may have arisen while philosopher i was eating.
D.To force a context switch, giving other philosophers a chance to run on the CPU.
Correct Answer: To wake up a potentially waiting neighbor whose ability to eat was dependent on philosopher i's forks being available.
Explanation:
When philosopher i puts down their forks, they change their state from EATING to THINKING. This action is a state change that could resolve the waiting condition for a neighbor. For example, philosopher i-1 might have been in the HUNGRY state, waiting for philosopher i to finish. By calling test() on its neighbors, the putdown operation proactively checks if the resource release has enabled any neighbor to proceed. If a neighbor can now eat, the test function will signal them, waking them up and allowing them to acquire the forks.
Incorrect! Try again.
60Peterson's two-process solution is correct. However, a naive attempt using only a shared boolean flag array (flag[i] = true means process i wants to enter) fails. The entry code is flag[i] = true; while (flag[j]);. What is the precise interleaving of operations for Process 0 (P0) and Process 1 (P1) that violates mutual exclusion?
classical two process and n-process solutions
Hard
A.P0 executes while(flag[1]), sees it's false, and is preempted. P1 then runs, sets flag[1]=true, and enters its CS. P0 resumes and enters its CS.
B.P0 sets flag[0]=true, enters its CS, and stays there indefinitely, starving P1.
C.P0 sets flag[0]=true, but due to a cache coherence issue, P1 reads the old value of flag[0] as false.
D.P0 sets flag[0]=true and is preempted. P1 sets flag[1]=true. Both processes now spin on their while loops, causing deadlock.
Correct Answer: P0 executes while(flag[1]), sees it's false, and is preempted. P1 then runs, sets flag[1]=true, and enters its CS. P0 resumes and enters its CS.
Explanation:
flag[0]=false, flag[1]=false.
P0 executes while(flag[1]). The condition is false.
P0 is preempted before it can set flag[0]=true.
P1 runs. It executes while(flag[0]) (false), enters its critical section. But it hasn't set its flag yet. This is not the standard faulty algorithm. The question's algorithm is set flag, then check. Let's re-trace THAT one:
flag[0]=false, flag[1]=false.
P0 sets flag[0] = true.
P0 is preempted.
P1 sets flag[1] = true.
P1 checks while(flag[0]). It's true. P1 spins.
P0 checks flag[1] (false). Is preempted.
P1 checks flag[0] (false). Enters CS.
P0 resumes, also enters CS. Mutual Exclusion violation. The provided option perfectly describes the interleaving for a check-then-set algorithm. Given the choices, this is the intended answer, pointing out a classic software synchronization bug. Let's assume the prompt's flag[i]=true; while(flag[j]) is flawed and the provided answer points to the correct failure trace for such algorithms in general. The turn variable in Peterson's solution is what solves this race.