Copyright Notice: Copyright by CMPUT 379, U. of Alberta, course instructor (E. Elmallah). All rights reserved. Do not post any part on a publicly-available Web site.
Question 3 (v4) [10 points]
The program below is supposed to endlessly print on the standard output two verses by Shake- speare, one after another in succession. It is also an attempt to implement the ¡®strict alterna- tion¡± technique for mutual exclusion. Two processes are responsible for printing one verse each, and they share a resource: the common output stream.
#include
Copyright By PowCoder代写 加微信 powcoder
int main () {
int turn= 0; /* 1: Othello¡¯s turn; 0: Iago¡¯s turn . */
if (fork()) { /* Othello */
while(1) {
while (turn == 0) ; /* do nothing */
printf (“Why he hath ensnared my soul and body? \n”);
else { /* Iago */
while(1) {
while (turn == 1) ; /* do nothing */
printf (“Demand me nothing, what you know, you know \n”);
1. What does the code display? Why?
2. If the code does not display the verses endlessly and in alternation (as required) then explain how it can be fixed. You may only use system calls and libraries that we covered thus far. Outline your strategy in one paragraph. In another paragraph write the system or function calls you need, and indicate how you use them.
University of Alberta examination University of Alberta examination
University of Alberta examination
University of Alberta examination University of Alberta examination
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com