Question: Write a simple program (example code available on Canvas; can be used as starting point) where processes synchronize via polling such that a process A
Question 1: Shared Memory (15 pts): Write a simple program (example code available on Canvas; can be used as starting point) where processes synchronize via polling such that a process A prints out the strings of two other separate writing processes (B first and then C second) from shared memory. Process A needs to 'wait' by polling until B and C finish writing their strings to memory. Each of processes A,B and C should be in different code files. Create TWO different shared memory locations: (i) one for storing the integer identifier and (ii) for storing the string. Here is the sequence of events that needs to be implemented: 1. Process A writes " 10" to the integer shared memory location. It also writes the string "I am Process A" into the string shared memory location and prints it out. Process A then waits until B and C completes. 2. Process B first checks if the Integer shared memory location has a " 10" in it. When true, it writes the string "I am Process B" into the string shared memory location and then signals A \& C that it is complete by writing "20" into the integer shared memory location (note: B must wait to write into the integer shared memory location until after process A writes " 10 " there). Then process B quits. 3. Process C writes the string "I am Process C " into the string shared memory and then signals A that it is complete by writing " 30 " into the integer shared memory location (note: C must wait until process B writes " 20 " into the integer shared memory). Then process C quits. 4. Process A needs to keep polling the integer shared memory location continuously. After process B writes "I am Process B", process A should be able to print it out. Similarly, after process C writes "I am Process C, process A needs to be able to print it out. Here some ad-hoc synchronization is needed. Specifically, consider using usleep() function to delay processes B and C between writing the string and the integer to give process A a chance to poll and print. Adjust the delay such that prints happen properly. 5. Process A is the last one to quit and prints out a "GoodBye" message at the very end before quitting. Deliverable: THREE different code files; one each for Process A, B and C
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
