zoukankan      html  css  js  c++  java
  • 东南大学《操作系统》课程作业 第七章

    1 - Consider the traffic deadlock depicted in the following Figure.
    image
    a. Show that the four necessary conditions for deadlock indeed hold in this example.
    b. State a simple rule for avoiding deadlocks in this system.

    a. 互斥:“路面上的每个位置”资源只能由一辆车占有;
    占有并等待:任何一辆车都占有当前位置,并且等待前方位置,不会让出;
    非抢占:调度者无法从某个位置移除一辆车;
    循环等待:从图中可以明显看出,所有车的等待资源构成了一个环形。
    b. 可以消灭占有并等待条件。规定当一辆车将汇入某位置时,该位置不能有另一辆车也将汇入。即需要申请该位置,并且仅有一辆车可以分配到使用权。

    2 - Consider the deadlock situation that could occur in the dining-philosophers problem when the philosophers obtain the chopsticks one at a time. Discuss how the four necessary conditions for deadlock indeed hold in this setting. Discuss how deadlocks could be avoided by eliminating any one of the four conditions.
    该情景下,死锁是可能发生的。考虑四个必要条件。互斥:“筷子”资源只能由一个哲学家占有;占有并等待:哲学家在获得筷子后会占有该筷子,并等待另一只筷子,而不会主动释放筷子;非抢占:不能从哲学家手上强行夺走筷子;循环等待:哲学家的“筷子等待链”显然可能构成环形。
    可以消灭占有并等待条件。规定哲学家在等待另一只筷子一段时间后,主动释放手上的一只筷子。

    3 - Compare the circular-wait scheme with the deadlock-avoidance schemes (like the banker’s algorithm) with respect to the following issues:
    a. Runtime overheads
    b. System throughput

    应用死锁避免方法会增加运行时间代价,因为需要追踪资源分配情况并执行一定的算法。但进行死锁避免后,系统的并发性更好,比起循环等待的死锁预防方法可以支持更多的并发任务。从这个角度来看,系统的吞吐量增加了。

    4 - In a real computer system, neither the resources available nor the demands of processes for resources are consistent over long periods (months). Resources break or are replaced, new processes come and go, new resources are bought and added to the system. If deadlock is controlled by the banker’s algorithm, which of the following changes can be made safely (without introducing the possibility of deadlock), and under what circumstances?
    a. Increase Available (new resources added).
    b. Decrease Available (resource permanently removed from system)
    c. Increase Max for one process (the process needs more resources than allowed, it may want more)
    d. Decrease Max for one process (the process decides it does not need that many resources)
    e. Increase the number of processes.
    f. Decrease the number of processes.

    a. 增加可用实例数量Available,显而易见不会带来新的安全问题;
    b. 减少可用实例数量Available可能导致某些进程分配不到请求的资源;
    c. 进程需要更多最大资源Max,可能导致其分配不到足够量的资源;
    d. 进程减少最大资源需求Max,显而易见不会带来新的安全问题;
    e. 增加进程数量时,只要当给该进程分配资源后,系统仍处于安全状态,就不会带来问题;
    f. 减少进程数量,显而易见不会带来新的安全问题。

    5 - Consider a system consisting of m resources of the same type, being shared by n processes. Resources can be requested and released by processes only one at a time. Show that the system is deadlock free if the following two conditions hold:
    a. The maximum need of each process is between 1 and m resources
    b. The sum of all maximum needs is less than m + n

    由a知道\(1≤Max_i≤m,∀i\)
    由b知道\(∑_n Max_i <m+n\),即\(∑_n(Need_i+Allocation_i)<m+n\)
    假设发生死锁,则至少有\(∑_n Allocation_i =m\)
    \(∑_n Need_i <n\),这意味着存在一个进程\(P_j\),满足\(Need_j=0\)。又\(Max_j≥1\),则\(Allocation_j≥1\)。只要这样的进程释放已Allocate的资源,在经历若干轮资源重新分配后,即可解除死锁状态。

    6 - Consider the following snapshot of a system: Using the banker’s algorithm, determine whether or not each of the following states is unsafe. If the state is safe, illustrate the order in which the threads may complete. Otherwise, illustrate why the state is unsafe.
    a. Available = (2, 2, 2, 3); b. Available = (4, 4, 1, 1)
    c. Available = (3, 0, 1, 4); d. Available = (1, 5, 2, 2)

    image
    image
    image

    7 - Consider the following snapshot of a system: Answer the following questions using the banker’s algorithm:
    a. Illustrate that the system is in a safe state by demonstrating an order in which the threads may complete.
    b. If a request from thread T4 arrives for (2, 2, 2, 4), can the request be granted immediately?
    c. If a request from thread T2 arrives for (0, 1, 1, 0), can the request be granted immediately?
    d. If a request from thread T3 arrives for (2, 2, 1, 2), can the request be granted immediately?

    image
    image
    b. 不能。如果立即满足该请求,则初始Available变为(0, 0, 0, 0),系统陷入不安全状态。
    c. 不能。如果立即满足该请求,则初始Available变为(2, 1, 1, 4),系统陷入不安全状态。
    d. 不能。如果立即满足该请求,则初始Available变为(0, 0, 1, 2),系统陷入不安全状态。

  • 相关阅读:
    【BZOJ】2209: [Jsoi2011]括号序列(splay)
    【BZOJ】1251: 序列终结者(splay)
    【UOJ】【UR #2】猪猪侠再战括号序列(splay/贪心)
    【BZOJ】3781: 小B的询问(莫队算法)
    【BZOJ】3289: Mato的文件管理(莫队算法+树状数组)
    【BZOJ】2038: [2009国家集训队]小Z的袜子(hose)(组合计数+概率+莫队算法+分块)
    【SPOJ】7258. Lexicographical Substring Search(后缀自动机)
    vue 中 event.stopPropagation() 和event.preventDefault() 使用
    Vue 中 使用v-show
    Vue v-if以及 v-else 的使用
  • 原文地址:https://www.cnblogs.com/zxuuu/p/15631265.html
Copyright © 2011-2022 走看看