Concepts of Programming Languages

(Sean Pound) #1

628 Chapter 13 Concurrency



  1. Busy waiting is a method whereby a task waits for a given event by con-
    tinuously checking for that event to occur. What is the main problem
    with this approach?

  2. In the producer-consumer example of Section 13.3, suppose that we
    incorrectly replaced the release(access) in the consumer process
    with wait(access). What would be the result of this error on execu-
    tion of the system?

  3. From a book on assembly language programming for a computer that
    uses an Intel Pentium processor, determine what instructions are pro-
    vided to support the construction of semaphores.

  4. Suppose two tasks, A and B, must use the shared variable Buf_Size.
    Task A adds 2 to Buf_Size, and task B subtracts 1 from it. Assume that
    such arithmetic operations are done by the three-step process of fetching
    the current value, performing the arithmetic, and putting the new value
    back. In the absence of competition synchronization, what sequences of
    events are possible and what values result from these operations? Assume
    that the initial value of Buf_Size is 6.

  5. Compare the Java competition synchronization mechanism with that
    of Ada.

  6. Compare the Java cooperation synchronization mechanism with that of
    Ada.

  7. What happens if a monitor procedure calls another procedure in the
    same monitor?

  8. Explain the relative safety of cooperation synchronization using sema-
    phores and using Ada’s when clauses in tasks.


PROGRAMMING EXERCISES



  1. Write an Ada task to implement general semaphores.

  2. Write an Ada task to manage a shared buffer such as the one in our
    example, but use the semaphore task from Programming Exercise 1.

  3. Define semaphores in Ada and use them to provide both cooperation
    and competition synchronization in the shared-buffer example.

  4. Write Programming Exercise 3 using Java.

  5. Write the shared-buffer example of the chapter in C#.

  6. The reader-writer problem can be stated as follows: A shared memory
    location can be concurrently read by any number of tasks, but when a
    task must write to the shared memory location, it must have exclusive
    access. Write a Java program for the reader-writer problem.

  7. Write Programming Exercise 6 using Ada.

  8. Write Programming Exercise 6 using C#.

Free download pdf