Date: Mon, 11 Nov 1996 17:25:25 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Wed, 07 Feb 1996 18:25:16 GMT Content-length: 2712 CS 537 - Quiz #1
UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department
CS 537
Spring 1996
Bart Miller
Quiz #1
Wednesday, February 7

Concurrent and Cooperating Processes

For the following two example programs, you are to describe what will be the output when each program is run. If there is more than one possible output, describe all the possibilities. Here are some general important facts:

Problem 1

Initialization
 int X = 0;
Process A
 while (X == 0) {  
   // do nothing
 }
 cout << "a";
Process B
 cout << "b";
 X = 1;
Describe the output here:

ba
The while-loop keeps executing until Process B has a chance to set X to 1. This is called "spinning" or "busy waiting".

Problem 2

Initialization
 int X = 0;
 int Y = 0;
Process A
 while (X == 0) {  
   // do nothing
 }
 cout << "a";
 Y = 1;
 Y = 0;
 cout << "d";
 Y = 1;
Process B
 cout << "b";
 X = 1;
 while (Y == 0) {  
   // do nothing
 }
 cout << "c";
Describe the output here:

The output will be either:

badc
or:
bacd
The difference depends on whether the dispatcher switches processes between first time Y is set to 1 and the time that Y is set to 0


Last modified: Wed Feb 7 12:25:15 CST 1996 by bart