7-sol - CHAPTER 7 Deadlocks Practice Exercises 7.1 List...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
7 CHAPTER Deadlocks Practice Exercises 7.1 List three examples of deadlocks that are not related to a computer- system environment. Answer: • Two cars crossing a single-lane bridge from opposite directions. • A person going down a ladder while another person is climbing up the ladder. • Two trains traveling toward each other on the same track. • Two carpenters who must pound nails. There is a single hammer and a single bucket of nails. Deadlock occurs if one carpenter has the hammer and the other carpenter has the nails. 7.2 Suppose that a system is in an unsafe state. Show that it is possible for the processes to complete their execution without entering a deadlock state. Answer: An unsafe state may not necessarily lead to deadlock, it just means that we cannot guarantee that deadlock will not occur. Thus, it is possible that a system in an unsafe state may still allow all processes to complete without deadlock occurring. Consider the situation where a system has 12 resources allocated among processes P 0 , P 1 ,and P 2 .The resources are allocated according to the following policy: Max Current Need P 0 10 5 5 P 1 4 2 2 P 2 9 3 6 21
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
22 Chapter 7 Deadlocks for(inti=0;i<n; i++) { // first find a thread that can finish for(intj=0;j<n; j++) { if (!finish[j]) { boolean temp = true; for(intk=0;k<m; k++) { if (need[j][k] > work[k]) temp = false; } if (temp) { // if this thread can finish finish[j] = true; for(intx=0;x<m; x++) work[x] += work[j][x]; } } } } Figure 7.1 Banker’s algorithm safety algorithm. Currently there are two resources available. This system is in an un- safe state as process P 1 could complete, thereby freeing a total of four resources. But we cannot guarantee that processes P 0 and P 2 can com- plete. However, it is possible that a process may release resources before requesting any further. For example, process P 2
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/03/2009 for the course IT OS taught by Professor Dr.stephan during the Winter '09 term at Abu Dhabi University.

Page1 / 4

7-sol - CHAPTER 7 Deadlocks Practice Exercises 7.1 List...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online