628 Chapter 13 Concurrency
- 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? - 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? - 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. - 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. - Compare the Java competition synchronization mechanism with that
of Ada. - Compare the Java cooperation synchronization mechanism with that of
Ada. - What happens if a monitor procedure calls another procedure in the
same monitor? - Explain the relative safety of cooperation synchronization using sema-
phores and using Ada’s when clauses in tasks.
PROGRAMMING EXERCISES
- Write an Ada task to implement general semaphores.
- 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. - Define semaphores in Ada and use them to provide both cooperation
and competition synchronization in the shared-buffer example. - Write Programming Exercise 3 using Java.
- Write the shared-buffer example of the chapter in C#.
- 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. - Write Programming Exercise 6 using Ada.
- Write Programming Exercise 6 using C#.