Deadlock Definition
What is a deadlock in the context of concurrent programming?
- A situation where a program crashes due to memory errors.
- A situation where two or more threads are blocked indefinitely, waiting for each other to release resources.
- A condition where a thread is temporarily suspended.
- A type of race condition that corrupts data.
- A compiler error that prevents the program from running.
Necessary Conditions
Which of the following is NOT one of the four necessary conditions for a deadlock to occur?
- Mutual exclusion
- Hold and wait
- No preemption
- Circular wait
- Priority inversion
Mutual Exclusion
What does the 'mutual exclusion' condition for deadlock mean?
- Multiple threads can access a resource simultaneously.
- A resource can only be held by one thread at a time.
- Threads are excluded from accessing certain parts of memory.
- The operating system excludes certain threads from running.
- Threads must exclude each other from using the CPU.
Hold and Wait Explained
Which scenario best describes the 'hold and wait' condition in a deadlock?
- A thread continuously waits for a resource without releasing any resources it already holds.
- A thread releases all its resources before requesting any new ones.
- A thread holds multiple resources and then waits for a specific amount of time before releasing them.
- A thread waits indefinitely for a resource, even if other resources are available.
- A thread attempts to acquire a resource that is currently being held by another thread.
No Preemption
What does 'no preemption' signify in the context of deadlock conditions?
- A resource can be forcibly taken away from a thread holding it.
- A thread can request a resource before releasing its current resources.
- A resource cannot be forcibly taken away from a thread holding it; the thread must release it voluntarily.
- The operating system cannot interrupt a running thread.
- Threads cannot be paused or resumed during execution.
Circular Wait Scenario
Which of the following scenarios exemplifies a 'circular wait' condition?
- Thread A waits for a resource held by Thread B, and Thread B waits for a resource held by Thread A.
- Thread A waits for a resource held by Thread B, but Thread B is not waiting for any resource.
- Thread A and Thread B both try to acquire the same resource simultaneously.
- Thread A and Thread B both release their resources before requesting new ones.
- Thread A waits for a resource, and Thread B is preempted while holding that resource.
Deadlock Prevention Strategy
Which strategy aims to prevent deadlocks by eliminating the 'circular wait' condition?
- Resource ordering (imposing a hierarchy on resource requests)
- Resource preemption (allowing resources to be forcibly taken away)
- Mutual exklusion
- Holding and Weighting
- Increasing CPU core count.
Deadlock Avoidance vs. Prevention
What is the key difference between deadlock prevention and deadlock avoidance?
- Prevention avoids deadlocks at runtime, while avoidance prevents them during compilation.
- Prevention aims to eliminate one or more of the necessary conditions, while avoidance allows deadlocks to potentially occur but avoids them by carefully allocating resources.
- Prevention is always more efficient than avoidance.
- Avoidance requires more overhead than prevention.
- They are the same.
Banker's Algorithm Purpose
What is the primary purpose of the Banker's Algorithm?
- To detect deadlocks after they have occurred.
- To prevent deadlocks by eliminating mutual exclusion.
- To avoid deadlocks by carefully allocating resources based on maximum potential needs.
- To resolve deadlocks by forcibly preempting resources.
- To ensure fair scheduling of threads.
Deadlock Detection Technique
Which technique is used to detect deadlocks when they occur?
- Resource allocation graphs
- Banker's algorithm
- Resource ordering
- Prevention
- Ignore and pray