Preview

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

Good Essays
Open Document
Open Document
810 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
If Two Heads Are Better Than One, Are Four Even Better?
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.

You May Also Find These Documents Helpful