

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Submission Steps: (1) YOUR NETID MUST BE AT THE TOP OF EVERY PAGE; (2) PRINT THE SOLUTIONS – SUBMISSION IN PAPER FORMAT; (3) BRING THE PRINTED HW1 SOLUTION TO ANDA OHLSSON’S OFFICE, 3120 SIEBEL CENTER BY 4PM
Problem 1 (10 Points)
Consider two processes running on two processors sharing a variable (critical section) in shared memory. Specify the two flag and turn solution (pseudo-code) for synchronizing two processes that satisfies mutual exclusion, progress and bounded wait synchronization conditions. Furthermore, explain (a) one assumption for the software to run correctly, and (b) how each variable contributes to the mutual exclusion, progress and/or bounded waiting requirements.
Problem 2: (20 Points)
Problem 3 (30 Points):
Consider the following functions that are shared by multiple processes:
static int count = 0; int increment(void) { count++; if (count > 5) { printf(“counter %d reached value > 5”, count); return 0; } return 1; }
int decrement(void) { while (count >5) { printf(“counter %d is > 5:”, count); count --; } if (count ==0) return 0; else return 1; }
Use any synchronization primitives (semaphores, mutex) to make the two functions atomic.
Problem 4 (10 Points):