Page 435 - Computer_Science_F5
P. 435
Computer Science Process 1 Resource 1 Waiting (c) No preemption: Once a process has
must request others while not holding
any. No hoarding.
Assigned
for
to
a resource, it cannot be forcibly taken
Process 2
away. No pushing in line.
FOR ONLINE READING ONLY
within the operating system that
Waiting Assigned (d) Semaphores: These are special flags
for Resource 2 to act like signals to control access to
shared resources. Semaphores work
Figure 7.11: Deadlock situation (to be as follows:
redrawn)
(i) Available resource: When a
Process 1 holds Resource 1 and requests resource like a file or printer
Resource 2. Process 2 holds Resource is free, the semaphore is set to
2 and requests Resource 1. In this case, “available” and so the process
Process 1 cannot proceed because it needs is allowed to use the shared
Resource 2, which is held by Process 2. resource.
Process 2 cannot proceed because it needs (ii) Requesting access: When a
Resource 1, which is held by Process process needs to use a resource,
it checks the semaphore. If it is
1. Both processes are waiting for each available, the process gets access,
other to release the resources, causing a and the semaphore is switched to
deadlock. “in use” to prevent others from
accessing the resource.
Deadlock preventive strategies (iii) Releasing the resource: When
No scheduling algorithm is perfect. The the process finishes using the
choice of an algorithm depends on the shared resource (e.g., finishing
workload and required performance levels. file reading or using a printer),
To minimize the possibility of deadlock it releases it, and the semaphore
happening, operating system developers is switched back to “available”,
can use preventive or avoidance strategies. allowing the next waiting process
There are three key techniques to prevent to proceed.
deadlock: (e) Critical sections: This is the actual
(a) Mutual exclusion: Only one process part of the process code where the
can access a resource at a time. This resource is used. It is similar to the
is like accessing only one teacher at time a student spends printing their
a time. document. The operating system
ensures only one process is in its
(b) Hold and wait: A process can only critical section using the resource
hold onto one resource at a time and at a time.
426
for Advanced Secondary Schools
Computer Science Form 5.indd 426 23/07/2024 12:34

