


































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



































CS 234 Concurrent Programming module 1
Correct Answer: To decrement the semaphore's value and block if the result is negative Rationale: The wait (P) operation decrements the semaphore's value and blocks the calling thread if the value becomes negative, indicating the resource is unavailable. The signal (V) operation increments the value and wakes waiting threads. Wait does not reset or merely check the value.
Semaphores are lower-level primitives. Monitors are not hardware devices or busy- wait loops. They provide structured synchronization.
Correct Answer: A problem involving philosophers who must share a limited number of forks to eat Rationale: The dining philosophers problem models a group of philosophers who alternate between thinking and eating, needing two forks to eat, with only one fork between each pair. It illustrates synchronization challenges like deadlock and starvation. It is not about sorting, networking, or prime numbers.
involves fork sharing, and sleeping barber involves customer service. Each illustrates different synchronization issues.
Rationale: A lock is a synchronization mechanism that ensures only one thread can enter a critical section at a time, providing mutual exclusion. It does not prevent all access to shared data, increase speed, or allow simultaneous critical section execution. Locks are fundamental to concurrent programming.
A) A synchronization primitive that provides mutual exclusion B) A type of semaphore that counts resources C) A condition variable for signaling D) A thread scheduling algorithm Correct Answer: A synchronization primitive that provides mutual exclusion Rationale: A mutex (mutual exclusion) is a lock that ensures only one thread can access a critical section at a time. It is a binary semaphore-like construct. It is not a counting semaphore, condition variable, or scheduling algorithm. Mutexes are widely used for protecting shared data.
A) To release the associated lock and block until signaled B) To acquire the associated lock C) To wake up other waiting threads D) To check the condition without blocking Correct Answer: To release the associated lock and block until signaled Rationale: The wait operation atomically releases the associated lock and blocks the calling thread until another thread signals the condition variable. It does not acquire locks, wake other threads, or merely check the condition. When signaled, wait reacquires the lock before returning.
Correct Answer: Monitors provide automatic mutual exclusion, while semaphores require explicit wait and signal Rationale: Monitors automatically ensure mutual exclusion for their procedures, while semaphores require programmers to explicitly call wait and signal. Semaphores are language-independent, and both can be used for mutual exclusion. Monitors are higher-level constructs.
B) To write concurrent programs for the user C) To eliminate all race conditions automatically D) To prevent threads from communicating Correct Answer: To provide synchronization primitives and thread scheduling Rationale: The operating system provides synchronization primitives (locks, semaphores) and schedules threads on available processors. It does not write programs, automatically eliminate race conditions, or prevent communication. The OS enables concurrent execution and resource management.
Rationale: Thread scheduling decides the order in which threads execute on available processors. It does not create, destroy, or synchronize threads. Scheduling policies affect performance, fairness, and responsiveness. The scheduler is a core OS component.
Rationale: The fork-join framework recursively divides a task into smaller subtasks that can be executed in parallel, then combines their results. It does not create processes, eliminate synchronization, or store data in buffers. It is designed for divide-and-conquer algorithms.