Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 385: Homework 3 - Deadlock and Resource Allocation, Assignments of Operating Systems

Information on 2-phase commit, deadlock, and resource allocation. It includes instructions for implementing get read lock and get write lock code, identifying potential deadlock scenarios, and writing resource allocation/release routines for dijkstra's conditions. It also includes exercises on wait-for graphs and banker's algorithm.

Typology: Assignments

Pre 2010

Uploaded on 07/22/2009

koofers-user-bgz
koofers-user-bgz 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 385: HW3–Due 31 Oct
Jon A. Solworth
October 26, 2003
1. In 2phase commit, if the deadlock occurs the transaction must abort. This abort is
part of the atomic operation and is performed by waiting a fixed amount of time for a
lock (say 1 second) and if it is not obtained, all locks are released all locations updated
by the transaction are restored, and the program branches back to the start of the
transaction.
Implement both get read lock and get write lock code implementing abort.
2. Can the following rules lead to deadlock? If so, give an example or if not explain why
not.
(a) Each process runs at a different (fixed) priority. If a higher priority process would
block on a resource held by a lower priority process, it kills the low priority process.
(b) Resources are numbered by integers. All odd numbered resources are requested
before any even even ones.
(c) Resources are requested in any order, but it is possible to time-share the resource
by 1) saving the state associated with one processes use of the resource and 2)
restoring the state associated with another process.
(d) Resources are numbered 0 through 5. A process requests either resource 0 or 5,
then 3 or 4, and then may request 1 and then may request 2.
(e) If all the resources requested are available they are allocaated otherwise the re-
questing process releases all the resources it holds.
3. Consider a systen with 3 resources A,B, and Cwith respective quantities NA,NB,
NC. Write a set of resource allocation/release routines (with error checking) for each
of Dijkstra’s 4 conditions which avoids deadlock by denying that condition (that is,
you should have 4 sets of routines).
4. In the following wait-for graph, is the system in deadlock?
1
pf3

Partial preview of the text

Download CS 385: Homework 3 - Deadlock and Resource Allocation and more Assignments Operating Systems in PDF only on Docsity!

CS 385: HW3–Due 31 Oct

Jon A. Solworth

October 26, 2003

  1. In 2phase commit, if the deadlock occurs the transaction must abort. This abort is part of the atomic operation and is performed by waiting a fixed amount of time for a lock (say 1 second) and if it is not obtained, all locks are released all locations updated by the transaction are restored, and the program branches back to the start of the transaction. Implement both get read lock and get write lock code implementing abort.
  2. Can the following rules lead to deadlock? If so, give an example or if not explain why not.

(a) Each process runs at a different (fixed) priority. If a higher priority process would block on a resource held by a lower priority process, it kills the low priority process. (b) Resources are numbered by integers. All odd numbered resources are requested before any even even ones. (c) Resources are requested in any order, but it is possible to time-share the resource by 1) saving the state associated with one processes use of the resource and 2) restoring the state associated with another process. (d) Resources are numbered 0 through 5. A process requests either resource 0 or 5, then 3 or 4, and then may request 1 and then may request 2. (e) If all the resources requested are available they are allocaated otherwise the re- questing process releases all the resources it holds.

  1. Consider a systen with 3 resources A, B, and C with respective quantities NA, NB , NC. Write a set of resource allocation/release routines (with error checking) for each of Dijkstra’s 4 conditions which avoids deadlock by denying that condition (that is, you should have 4 sets of routines).
  2. In the following wait-for graph, is the system in deadlock?
  1. Given the following banker’s algorithm configuration, answer the below questions using a banker’s algorithm simulation,: - Is the below configuration safe? - Is the allocation request of 1 unit of R 0 to p 1 safe?

Variable R 0 R 1 R 2 total resources 3 4 2 allocated/need p 0 0/3 2/2 1/ allocated/need p 1 1/2 1/0 0/ allocated/need p 2 0/1 1/2 0/

  1. In the following configuration, use the banker’s algorithm to determine whether the system is in deadlock.

Variable R 0 R 1 R 2 total resources 3 2 1 allocated to p 0 1 0 1 allocated to p 1 1 1 0 allocated to p 2 0 1 0

Assuming that p 1 is waiting for 1 unit of R 2 and p 2 is waiting for 2 units of R 0.

  1. Consider the following cases, and describe whether starvation is possible and if so how and if not, why not.