25-Comp-A5 Operating Systems · December 2014
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
(a) Given. $m=7$ identical resources; $n=3$ processes; each process's maximum simultaneous hold is $k=3$; resources requested/released one at a time; no deadlock-avoidance algorithm. Find. Whether deadlock can occur. Approach. Apply the standard sufficient condition: with $n$ processes each needing at most $k$ units of a single resource type and $m$ total units, deadlock is impossible whenever $m \ge n(k-1)+1$, because that many units guarantee at least one process can always complete.
The system sits exactly on the safe threshold: $m=7$ is the minimum number of resources for which this guarantee holds for $n=3,\ k=3$ (one fewer, $m=6$, would allow all three processes to hold 2 each and block forever, a genuine deadlock).
(b) Deadlock is a state in which a set of processes are each waiting for an event (typically resource release) that only another process in the same set can cause, so none of them can ever proceed — it is provably permanent (formally, a cycle in the resource-allocation graph under the single-instance case) and requires all four Coffman conditions (mutual exclusion, hold-and-wait, no preemption, circular wait) simultaneously. Starvation (indefinite postponement) is a process being perpetually denied a resource or CPU time it needs, not because of a circular dependency but because of how the scheduling/allocation policy makes its choices — e.g. a strict fixed-priority scheduler that always favours higher-priority processes can starve a low-priority process even though no deadlock cycle exists and the resource does become free repeatedly. Starvation is typically curable by aging (gradually raising a waiting process's priority); deadlock cannot be "waited out" and requires detection/recovery or prevention/avoidance.
(c) Sequential access requires reading or writing data in a fixed, ordered progression from wherever the last operation left off — to reach byte $N$, everything before it must first be traversed (the natural model for a linked-list-organized file, or physically for magnetic tape). Random access lets any block be reached directly, in roughly constant time regardless of what was accessed previously, by supplying an address (e.g. a track/sector or a byte offset) — disks support this natively because the head can seek directly to any track. Random access does still incur a variable seek-time-plus-rotational-latency cost that depends on the distance moved (which is exactly what SSTF/SCAN in part (b) are trying to minimize), but that cost is bounded and address-based, unlike sequential access's requirement to pass through every intervening block.
(d) No. Deadlock requires all four Coffman conditions to hold simultaneously, and the very first — mutual exclusion — is absent for pure read access: any number of processes can hold a shared (read) lock on the same file at the same time without conflict, since reading never modifies the file and there is nothing to protect one reader from another. With no process ever forced to wait for exclusive access to a read-only file, no process can be blocked waiting on another process's read-only file hold, so no circular-wait chain involving these files can ever form. (This changes immediately if even one process needs write access, since a writer requires exclusive access and reintroduces mutual exclusion.)
| Part | Result |
|---|---|
| (a) Deadlock possible? | No — $n(k-1)+1=7\le m=7$ |
| (d) Deadlock from read-only file sharing? | No — mutual exclusion condition never arises |