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

  • Satisfactory Essays

    SD1230 Lab 1

    • 239 Words
    • 2 Pages

    2. What type of instruction is used to execute different code based on a condition? -Jumps…

    • 239 Words
    • 2 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
  • Satisfactory Essays

    Nt1310 Unit 1 Study Guide

    • 378 Words
    • 2 Pages

    _____________ is the ability of a central processing unit (CPU) or a single core in a multi-core processor to execute multiple processesor threads concurrently…

    • 378 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Homework Unit 3

    • 354 Words
    • 2 Pages

    1. Statements are execute in order according to the program code. Complex programs can need the help of a decision structure. Statements have to be true to be executed.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    unit 7 assignment 1

    • 431 Words
    • 2 Pages

    5. What three actions do count-controlled loops typically perform using the counter variable? Initialization: Before the loop begins, the counter variable is initialized to a starting value. Test : The loop tests the counter variable by comparing it to a maximum value. If the counter variable is less than or equal to the maximum, the loop iterates. If the counter is greater than the maximum value, the program exits the loop. Increment : To increment a variable means to increase its value. During each iteration, the loop increments the counter variable by adding a predetermined amount to it…

    • 431 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Unit 16 Ao1

    • 529 Words
    • 3 Pages

    All programs are written to do something, their purpose may be to perform a calculation or to run a computer game, but all programs will perform a task, also known as a process. All programs take the stricter of input, process to output. Th input includes user controls such as keyboard, mouse, game controller, voice and so on. It will also include data from the user, computer or other programs.…

    • 529 Words
    • 3 Pages
    Good 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
  • Good Essays

    pt1420 exam review

    • 738 Words
    • 3 Pages

    What is a logical design that controls the order in which a set of statements execute?…

    • 738 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    unit 3

    • 313 Words
    • 2 Pages

    4. Assume the variables result, w, x, y , and z are 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?…

    • 313 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

    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
  • 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
  • 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
  • Satisfactory Essays

    Faith Integration

    • 613 Words
    • 3 Pages

    The processor could keep track of what locations are associated with each process and limit access to locations that are outside of a program's extent. By using base and limits registers and by performing a check for every memory access, information regarding the extent of a program's memory could be maintained…

    • 613 Words
    • 3 Pages
    Satisfactory Essays
  • 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