If Two Heads Are Better Than One, Are Four Even Better?

Only available on StudyMode
  • Topic: Deadlock, Process, Concurrency
  • Pages : 5 (810 words )
  • Download(s) : 357
  • Published : May 6, 2011
Open Document
Text Preview
Chapter 5

Questions:

1. List four design issues for which the concept of concurrency is relevant.

2. What is the basic requirement for the execution of concurrent processes?

Problems

1. Consider a concurrent program with two processes, p and q, defines as follows. A, B, C, D and E are arbitrary atomic ( indivisible ) statements. Assume that the main program ( not shown ) does a parbegin of the two processes.

Void p()Void q()
{{
A;D;
B;E;
C;}
}
Show all the possible interleavings of the execution of preceding two processes (Show this by giving execution “traces” in terms of the atomic statements)

2. Consider the following program:

const int n = 50;
int tally;

void total()
{
int count;
for ( count = 1; count 0)
s.count--;
else
place this process in s.queue;
block;
}

void semSignal(s)
{
if (there is at least one process blocked on semaphore s)
remove a process P from s.queue;
place process P on ready list;
else
s.count++;
}

Compare this set of definitions with that of Figure 5.3. Note one difference: With the preceding definition, a semaphore can never take on a negative value. Is there any difference in the effect of these two sets of definitions when used in programs? That is, could you substitute one set for the other without altering the meaning of the program?

5. (5.3) Given the following code:
Program concurrency;
var x:integer(:=0);
y:integer(:=0);
procedure threadA();
begin
x=1;(* statement 1 *)
y=y+x;(* statement 2 *)
end;
begin(* main program *)
parbegin
threadA();
threadB();
parend
end.
That is, suppose a process has two concurrent threads; one thread executes statements 1 and 2, and the other thread executes statements 3 and 4. List all the possible values of the variables when the code finishes executing - include the order the statements (1-4) must execute for each ending value. Assume statements 1-4 are atomic.

6 (5.4) Sketch the program outline below using general semaphores so that the processes ALWAYS terminate in the order A (any copy), B, A, A.
program As_and_Bs;
var { semaphore declarations }
procedure A();
begin
{P and V statements only }
end;
procedure B();
begin
{ P and V statements only }
end;
begin( * main program * )
parbegin
A();
A();
A();
B();
parend
end.

Chapter 6

Review Question
6.4 How can the hold-and-wait condition be prevented?

6.5 List two ways in which the no-preemption condition can be prevented.

6.7 What is the difference among deadlock avoidance, detection, and prevention?

Problem.
6.4 Consider the following snapshot of a system. There are no outstanding unsatisfied requests for resources. [pic]
a. Compute what each process still might request and display in the columns labeled “still needs.” b. Is this system currently in a safe or unsafe state? Why?
c. If a request from p3 arrives for (0,1,0,0), can that request be safely granted immediately? In what state (deadlocked,safe,unsafe) would immediately granting that whole request leave the system? Which processes, if any, are or may become deadlocked if this whole request is granted immediately?

6.5 Apply the deadlock detection algorithm of Section 6.4 to the following data and show the results. Available=(2 1 0 0) Request=[pic] Allocation= [pic]

6.10 Consider a system with a total of 150 units of memory, allocated to three processes as shown: |process |max |hold |
|1 |70 |45 |
|2 |60 |40 |
|3 |60 |15 |

Apply the banker’s algorithm to determine whether it would be safe to grant each of the following requests. If yes, indicate a sequence of terminations that could be guaranteed possible. If no, show the reduction of the resulting allocation table.

a) A fourth process...
tracking img