Chapter 8: Deadlocks in Operating Systems

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/87

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

88 Terms

1
New cards

What are the four necessary conditions that characterize deadlock?

1. Mutual exclusion: only one thread can use a resource at a time. 2. Hold and wait: a thread holding resources is waiting for more. 3. No preemption: resources can only be released voluntarily. 4. Circular wait: a set of threads is waiting in a circular chain.

2
New cards

What is the system model in the context of deadlocks?

The system consists of resources, including types like CPU cycles, memory space, and I/O devices, with each resource type having multiple instances.

3
New cards

How do threads utilize resources in a system?

Threads utilize resources by requesting, using, and releasing them.

4
New cards

What is a semaphore, and how is it used in deadlock scenarios?

A semaphore is a synchronization tool initialized to a value (e.g., 1) that controls access to resources. In deadlock scenarios, two threads may wait on each other's semaphores, leading to a deadlock.

5
New cards

What is a resource-allocation graph?

A resource-allocation graph consists of vertices representing threads and resource types, with edges indicating requests and assignments.

<p>A resource-allocation graph consists of vertices representing threads and resource types, with edges indicating requests and assignments.</p>
6
New cards

What does a request edge in a resource-allocation graph represent?

A request edge is a directed edge from a thread to a resource, indicating that the thread is requesting that resource.

7
New cards

What does an assignment edge in a resource-allocation graph represent?

An assignment edge is a directed edge from a resource to a thread, indicating that the resource is currently allocated to that thread.

8
New cards

What is the significance of cycles in a resource-allocation graph?

If the graph contains no cycles, there is no deadlock. If it contains a cycle, deadlock may occur if there is only one instance per resource type.

9
New cards

What is deadlock prevention?

Deadlock prevention involves ensuring that the system will never enter a deadlock state through specific strategies.

10
New cards

What is deadlock avoidance?

Deadlock avoidance is a method that allows the system to enter a deadlock state but takes measures to ensure it does not occur.

11
New cards

What is deadlock detection?

Deadlock detection involves identifying when a deadlock has occurred in the system.

12
New cards

What are the approaches for recovering from deadlock?

Recovery approaches may include terminating processes, rolling back processes to safe states, or preempting resources.

13
New cards

What is the banker's algorithm?

The banker's algorithm is a deadlock avoidance algorithm that allocates resources based on current needs and future requests to ensure safe states.

14
New cards

What is the role of mutex locks in deadlocks?

Mutex locks can lead to deadlocks when multiple threads hold locks and wait for each other to release them.

<p>Mutex locks can lead to deadlocks when multiple threads hold locks and wait for each other to release them.</p>
15
New cards

What is the difference between deadlock prevention and deadlock avoidance?

Deadlock prevention aims to ensure that the system never enters a deadlock state, while deadlock avoidance allows for the possibility of deadlocks but prevents them from occurring.

16
New cards

What happens if a resource-allocation graph contains multiple instances of a resource type?

If a graph contains a cycle but multiple instances of a resource type, there is a possibility of deadlock, but it is not guaranteed.

17
New cards

How can you identify a deadlock situation in a resource allocation graph?

A deadlock situation can be identified if there is a cycle in the graph where threads are waiting for resources held by each other.

18
New cards

What is the importance of the 'no preemption' condition in deadlock characterization?

The 'no preemption' condition means that once a resource is allocated to a thread, it cannot be forcibly taken away, which can lead to deadlock.

19
New cards

What does 'hold and wait' imply in the context of deadlocks?

'Hold and wait' implies that a thread holding one or more resources is waiting to acquire additional resources held by other threads.

20
New cards

What is the implication of having a cycle in a resource allocation graph?

A cycle in a resource allocation graph indicates a potential deadlock situation, especially if there is only one instance of each resource type.

21
New cards

What are the basic facts regarding cycles in resource-allocation graphs?

If the graph contains no cycles, there is no deadlock. If it contains a cycle, deadlock may occur depending on the number of resource instances.

22
New cards

What are the four necessary conditions for deadlock?

1. Mutual Exclusion 2. Hold and Wait 3. No Preemption 4. Circular Wait

23
New cards

What is the mutual exclusion condition in the context of deadlock?

Mutual Exclusion is not required for sharable resources (e.g., read-only files) but must hold for non-sharable resources.

24
New cards

How can the hold and wait condition be invalidated?

By guaranteeing that whenever a thread requests a resource, it does not hold any other resources, or by requiring threads to request all resources before execution or only when they have none allocated.

25
New cards

What are the potential downsides of invalidating the hold and wait condition?

Low resource utilization and possible starvation.

26
New cards

What does the no preemption condition entail in deadlock prevention?

If a process holding resources requests another resource that cannot be allocated, all held resources are released, and the thread is restarted only when it can regain its old and new requested resources.

27
New cards

How can circular wait be prevented?

By imposing a total ordering of all resource types and requiring that each thread requests resources in an increasing order of enumeration.

28
New cards

What is the purpose of deadlock avoidance?

To ensure that the system never enters a circular-wait condition by using a priori information about resource needs.

29
New cards

What is the simplest model for deadlock avoidance?

Each thread declares the maximum number of resources of each type that it may need.

30
New cards

What is a safe state in the context of resource allocation?

A system is in a safe state if there exists a sequence of threads such that each thread can be satisfied with currently available resources plus resources held by previously finished threads.

31
New cards

What happens if a system is in a safe state?

If a system is in a safe state, there are no deadlocks.

<p>If a system is in a safe state, there are no deadlocks.</p>
32
New cards

What does it mean if a system is in an unsafe state?

If a system is in an unsafe state, there is a possibility of deadlock.

33
New cards

What is the relationship between avoidance and unsafe states?

Avoidance ensures that a system will never enter an unsafe state.

34
New cards

How does the system determine if it can allocate a resource to a thread?

The system must decide if immediate allocation leaves the system in a safe state.

35
New cards

What is the definition of the resource-allocation state?

The resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.

36
New cards

What is the implication of a thread's resource needs not being immediately available?

The thread can wait until all previously finished threads have completed.

37
New cards

What occurs when a thread terminates in a safe state?

When a thread terminates, the next thread in the sequence can obtain its needed resources.

38
New cards

What is the significance of assigning unique numbers to resources?

It helps to impose an order in which resources must be acquired, preventing circular wait.

39
New cards

What is the consequence of a thread requesting resources in a non-increasing order?

It can lead to a circular wait condition, which is a necessary condition for deadlock.

40
New cards

What is starvation in the context of resource allocation?

Starvation occurs when a thread is perpetually denied the resources it needs to proceed.

41
New cards

What does it mean for a resource to be sharable?

Sharable resources can be accessed by multiple threads simultaneously without causing deadlock.

42
New cards

What is the importance of the maximum demand declaration by threads?

It allows the deadlock-avoidance algorithm to dynamically examine the resource-allocation state.

43
New cards

What are the two types of states in resource allocation?

Safe and Unsafe states.

44
New cards

What is the purpose of a resource-allocation graph?

To manage resource allocation between processes and prevent deadlocks.

45
New cards

What does a claim edge in a resource-allocation graph indicate?

It indicates that a process may request a resource.

46
New cards

What happens to a claim edge when a thread requests a resource?

It converts to a request edge.

47
New cards

What is the Banker's Algorithm used for?

To manage resource allocation when multiple instances of a resource type are available.

48
New cards

What must each thread do before requesting resources in the Banker's Algorithm?

Each thread must claim its maximum resource usage a priori.

49
New cards

What is the condition for granting a resource request in the resource-allocation graph?

The request can be granted only if it does not form a cycle in the graph.

50
New cards

What are the four data structures used in the Banker's Algorithm?

Available vector, Max matrix, Allocation matrix, Need matrix.

51
New cards

How is the Need matrix calculated in the Banker's Algorithm?

Need[i,j] = Max[i,j] - Allocation[i,j].

52
New cards

What is the first step in the Safety Algorithm?

Initialize Work to Available and Finish[i] to false for all processes.

53
New cards

What does the Safety Algorithm check for?

It checks if the system is in a safe state by ensuring all processes can finish.

54
New cards

What does the Resource-Request Algorithm determine?

It determines if a process can be granted its requested resources without exceeding limits.

55
New cards

What must be true for a request to be valid in the Resource-Request Algorithm?

Request must be less than or equal to Need and Available.

56
New cards

What happens if a process's request exceeds its maximum claim?

An error condition is raised.

57
New cards

What is the significance of the Finish vector in the Safety Algorithm?

It indicates whether a process has completed its execution.

58
New cards

What is the role of the Work vector in the Safety Algorithm?

It keeps track of the currently available resources.

59
New cards

What occurs in step 2 of the Safety Algorithm?

Find a process that can finish based on current Work and Need.

60
New cards

What is the outcome if no process can finish in the Safety Algorithm?

The algorithm concludes that the system is in an unsafe state.

61
New cards

What does the term 'unsafe state' imply in resource allocation?

It implies that there is a potential for deadlock.

62
New cards

What is the maximum claim of a process in the context of resource allocation?

The maximum number of instances of each resource type that a process may request.

63
New cards

What does the assignment edge represent in a resource-allocation graph?

It represents that a resource has been allocated to a thread.

64
New cards

What happens to the assignment edge when a resource is released?

It reconverts to a claim edge.

65
New cards

What is the first step in the resource allocation process for thread Ti in the Banker's Algorithm?

Modify the state by reducing Available by Requesti, increasing Allocationi by Requesti, and decreasing Needi by Requesti.

66
New cards

What happens if the system is in a safe state after a resource allocation?

The resources are allocated to thread Ti.

67
New cards

What happens if the system is in an unsafe state after a resource allocation?

Thread Ti must wait, and the old resource-allocation state is restored.

68
New cards

In the example of the Banker's Algorithm, how many resource types are there?

Three resource types: A, B, and C.

69
New cards

What is the total number of instances for resource type A in the example?

10 instances.

70
New cards

What is the total number of instances for resource type B in the example?

5 instances.

71
New cards

What is the total number of instances for resource type C in the example?

7 instances.

72
New cards

How is the Need matrix defined in the context of the Banker's Algorithm?

Need is defined as Max - Allocation.

73
New cards

What is the sequence that satisfies the safety criteria in the example provided?

< T1, T3, T4, T2, T0 >.

74
New cards

What is the first check performed when a thread requests resources in the example?

Check that Request ≤ Available.

75
New cards

What is the result of executing the safety algorithm for the request (1,0,2) by P1?

The sequence < T1, T3, T4, T0, T2 > satisfies the safety requirement.

76
New cards

What is the purpose of a deadlock detection algorithm?

To allow the system to enter a deadlock state and then detect it.

77
New cards

What is the wait-for graph used for in deadlock detection?

To represent threads as nodes and indicate which thread is waiting for which.

78
New cards

What does a cycle in the wait-for graph indicate?

The presence of a deadlock.

79
New cards

What is the time complexity of the algorithm to detect a cycle in a wait-for graph?

O(n^2) operations, where n is the number of vertices.

80
New cards

What does the detection algorithm initialize Work and Finish vectors to?

Work is initialized to Available, and Finish is initialized based on Allocation.

81
New cards

What does the detection algorithm check for in step 2?

Find an index i such that Finish[i] is false and Requesti ≤ Work.

82
New cards

What happens if no such index i exists in the detection algorithm?

Proceed to step 4.

83
New cards

What does the detection algorithm conclude if Finish[i] is false for some i?

The system is in a deadlock state.

84
New cards

What factors influence when to invoke the deadlock detection algorithm?

How often a deadlock is likely to occur and how many processes need to be rolled back.

85
New cards

What is one method of recovering from deadlock?

Abort all deadlocked threads or abort one process at a time until the deadlock cycle is eliminated.

86
New cards

What criteria can be used to decide which thread to abort in a deadlock recovery scenario?

Priority of the thread, computation time, resources used, resources needed, number of threads to terminate, and whether the thread is interactive or batch.

87
New cards

What is resource preemption in the context of deadlock recovery?

Selecting a victim to minimize cost and rolling back to a safe state.

88
New cards

What is a potential issue with resource preemption?

Starvation, where the same thread may always be picked as a victim.