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

  • Good Essays

    4. Find at least one use of parallel structure in the Declaration. What key terms are repeated in identical or equivalent constructions, and to what effect?…

    • 695 Words
    • 3 Pages
    Good Essays
  • Better Essays

    7) Global variables make debugging difficult because any statement in a program can change its value.…

    • 1580 Words
    • 11 Pages
    Better Essays
  • Satisfactory Essays

    3. When a module is executing, what happens when the end of the module is reached?…

    • 765 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    PT1420 Chapter 3 Review

    • 1062 Words
    • 8 Pages

    4. Assume the variables result, w, x, y, and z are all integers, and that w = 5, x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements?…

    • 1062 Words
    • 8 Pages
    Satisfactory Essays
  • Satisfactory Essays

    4.) Write assignment statements that perform the following operations with the variables a, b, and c:…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    6. Write a pseudocode statement that declares the variable total so it can hold integers. Initialize the variable with the value 0.…

    • 748 Words
    • 3 Pages
    Powerful Essays
  • Good Essays

    8. Is it possible that the instructions within a While statement might never be executed at all? Give an example.…

    • 610 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Pt1420 Assignment

    • 1058 Words
    • 5 Pages

    1) Initialization: the variable is initialized 2) Test: the loop tests the variable by comparing it to the maximum value 3) Increment: to increase the value during each iteration the loop increments the counter variable by adding 1 to it.…

    • 1058 Words
    • 5 Pages
    Satisfactory Essays
  • Satisfactory Essays

    call to suspend the execution of the thread for a given amount of time, say in µsecs.…

    • 299 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Prg 211

    • 393 Words
    • 2 Pages

    An if statement is basically a single block of instructions where the test condition have been met, then the statements will be executed sequentially. Otherwise, the statements are skipped over if the test condition failed.…

    • 393 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Nt1310 Unit 1 Study Guide

    • 378 Words
    • 2 Pages

    The simplest type of multithreading occurs when one thread runs until it is blocked by an event that normally would create a ___________…

    • 378 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3 Os

    • 1341 Words
    • 6 Pages

    +• Synchronization: With multiple active processes having potential access to shared address spaces or shared I/O resources, care must be taken to provide effective synchronization. Synchronization is a facility that enforces mutual exclusion and event…

    • 1341 Words
    • 6 Pages
    Good Essays
  • Satisfactory Essays

    UNIT 2

    • 470 Words
    • 3 Pages

    4.) Write assignment statements that perform the following operations with the variables a, b, and c:…

    • 470 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Comp122 Week 2 Homework

    • 301 Words
    • 2 Pages

    What values (if any) are assigned to x, y, and ch after each of these statements execute?…

    • 301 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Mcse 011(Mca 5)Ignou

    • 1946 Words
    • 8 Pages

    A.J.Bernstein has elaborated the work of data dependency and derived some conditions based on which we can decide the parallelism of instructions or processes. Bernstein conditions are based on the following two sets of variables: i) The Read set or input set RI that consists of memory locations read by the statement of instruction I1. ii) The Write set or output set WI that consists of memory locations written into by instruction I1. The sets RI and WI are not disjoint as the same locations are used for reading and writing by SI. The following are Bernstein Parallelism conditions which are used to determine whether statements are parallel or not: 1) Locations in R1 from which S1 reads and the locations W2 onto which S2 writes must be mutually exclusive. That means S1 does not read from any memory location onto which S2 writes. It can be denoted as: R1∩W2= 2) Similarly, locations in R2 from which S2 reads and the locations W1 onto which S1 writes must be mutually exclusive. That means S2 does not read from any memory location onto which S1 writes. It can be denoted as: R2∩W1= 3) The memory locations W1 and W2 onto which S1 and S2 write, should not be read by S1 and S2. That means R1 and R2 should be independent of W1 and W2. It can be denoted as : W1∩W2= To show the operation of Bernstein’s conditions, consider the following instructions of sequential program:…

    • 1946 Words
    • 8 Pages
    Good Essays