Question: You are writing code for the voting machines for an upcoming election. You use shared counters, one for each candidate to keep track of the

You are writing code for the voting machines for an upcoming election. You use shared counters, one for each candidate to keep track of the votes as they come from the different voting machines. You can think of each machine as a thread: every time it receives a vote, it increments a counter for that candidate. (a) Explain what could go wrong with this implementation if we do not use synchronization (b) Suggest two ways to use locks to solve this problem without changing the code other than adding the lock operations; which one is more conservative. (c) Consider the following improvement to the implementation suggested by a cs153 veteran: for each thread, maintain a local count of the votes, and then update the global count periodically. Do we still need synchronization? (d) Compare the implementation in c to the better of the two implementations in
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
