Lab 3 - Critical Sections
Due: 9:55 AM, Tuesday, March 1, 2005
This week's lab consists of questions to look at on your own (not to be turned in) and some questions to be turned in. The programing for this lab is considered a "laboratory program" for honor code purposes. You may discuss the programs with others, but what you turn in must be your own work.
You do not need to turn in answers to these questions. But they could certainly form the basis for potential exam questions.
Answer these questions in a plain text file named lab3.txt.
Write a C program that will list all possible orderings of the machine instructions generated for the critical sections of the Producer-Consumer example from class. Recall that the statements counter++ and counter- actually generate machine code such as
Producer | Consumer | ||
P1 | R0 = counter; | C1 | R1 = counter; |
P2 | R0 = R0 + 1; | C2 | R1 = R1 - 1; |
P3 | counter = R0; | C3 | counter = R1; |
Your program should list all possible interleavings of the statements P1, P2, P3, C1, C2, and C3. Also have your program print which interleavings produce a correct result (that counter has the same value it started with).
Write your program in a file called interleaving.c. (5 points)