In: Computer Science
1. Try running the deadlock simulator using the following command: java deadlock a 2 2 Explain why a deadlock does not occur.
2. There are two additional process command files ("b0.dat" and "b1.dat") in the distribution. Run the deadlock simulator with this command: java deadlock b 2 1 1 What happens?
Now try this: java deadlock b 2 1 2 Why does the first command result in a deadlock but the second does not? Explain your answer in terms of what is going on in the process command files, b0.dat and b1.dat.
CAN SOMEBODY EXPLAIN THE QUESTIONS.
Assume this is with the MOSS deadlock simulator.
QUESTION 1:
The first command is java deadlock a 2 2
As per the documentation, 'a' represents the prefix for the command
files; so a0.dat and a1.dat will be chosen because they have the
prefix 'a'.
The next parameter is the number of processes to be created, which
is 2 in this case
The third (and any parameters after that) represent the number of
instances to create for each resource. In this case, 2 instances
will be created for a single resource since there is only one
resource parameter.
For a deadlock to happen, there need to be a minimum of 2
resources, so for example, the following steps occuring
simultaneously causes a deadlock:
Process 1 requests resource 1 and gets it
Process 2 requests resource 2
and gets it
Process 1 requests resource 2 but it is locked by process
2 Process 1 requests resource 1 but
it is locked by process 2
Since there is only one resource here, no deadlocks can happen.
QUESTION 2:
This time, the command is java deadlock b 2 1 1
This means that command files with the prefix 'b' will be used,
specifically, b0.dat and b1.dat. The next parameter indicates that
2 processes will be running simultaneously. Finally, the last two
1's on the command line mean that 1 instance of the first type of
resource and 1 instance of the second type of resource will be
available.
This configuration can cause a deadlock (depending on commands in
b0.dat and b1.dat, which you will have to look into). Each of the
two processes can hold a lock on one of the resources (remember
there is only one instance of each resource, so only one process
can get a usable instance of a resource). And if the two processes
now try to lock the resource that the other one has, a deadlock
will result.
The next command is: java deadlock b 2 1 2
This creates two processes using the command files starting with
'b'; there are two processes; there is 1 instance of the first
resource and 2 instances of the second resource. In this case,
suppose one process has locked the first resource (of which there
is only one instance). If the second process also wants the first
resource, it ends up blocked (waiting). If both processes need the
second resource, it is not a problem, since there are 2 instances
of the second resource. Hence, the first process (which has
successfully locked the first process) will never be blocked and
will eventually complete its work and unlock the first resource.
Hence, we never have a situation with two processes both being
blocked, waiting for each other. Hence a deadlock cannot
occur.