


































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 3
Rationale: Deadlock recovery by process termination involves aborting one or more processes involved in the deadlock to break the circular wait. Resource preemption takes resources from processes, rollback restores a previous state, and deadlock avoidance prevents deadlocks before they occur. Termination is a common recovery method.
one of the four necessary conditions for deadlock. Releasing resources before requesting or allowing preemption would prevent it.
Rationale: A mutex can only be unlocked by the thread that locked it, providing ownership semantics. A semaphore can be signaled by any thread, making it more flexible for signaling between threads. Both can provide mutual exclusion, but a mutex is stricter about ownership.
Rationale: Starvation occurs when a thread is indefinitely postponed from accessing a resource, even though the resource is available. Deadlock involves circular waiting, livelock involves active but unproductive execution, and race conditions involve unpredictable timing. Starvation is a fairness issue.
A) To ensure that at least one of the necessary conditions for deadlock cannot occur B) To detect deadlocks after they occur C) To recover from deadlocks D) To ignore deadlocks Correct Answer: To ensure that at least one of the necessary conditions for deadlock cannot occur Rationale: Deadlock prevention techniques ensure that at least one of the four necessary conditions cannot hold, making deadlock impossible. Detection and recovery handle deadlocks after they occur. Prevention is proactive.
Correct Answer: To provide a way for threads to wait and be signaled within a lock Rationale: The Condition interface, used with ReentrantLock, provides await, signal, and signalAll methods, similar to monitor condition variables. It does not define data types, count threads, or create locks. Conditions enable fine-grained waiting and notification.
Rationale: ConcurrentHashMap is a thread-safe implementation of Map designed for concurrent access without external synchronization. ArrayList, HashMap, and LinkedList are not thread-safe and require external synchronization for concurrent use. Concurrent collections simplify concurrent programming.
Rationale: ReentrantLock provides a tryLock method that attempts to acquire the lock without blocking, allowing threads to proceed if the lock is unavailable. It is not always faster, requires explicit unlock, and is still a synchronization mechanism. This flexibility can prevent deadlocks.
A) To allow a set of threads to wait for each other at a common barrier point B) To provide mutual exclusion C) To store data permanently D) To create new threads Correct Answer: To allow a set of threads to wait for each other at a common barrier point Rationale: CyclicBarrier allows a fixed number of threads to wait for each other at a barrier point before proceeding, and can be reused. It is not for mutual exclusion, data storage, or thread creation. It is useful for parallel algorithms with phases.