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 upcomingelection. You use shared counters, one for each candidate to keep track

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) (2 point) Explain what could go wrong with this implementation if we do not use synchronization (b) (3 points) Suggest two ways to use locks or semaphores to solve this problem without changing the code other than adding the lock operations. Its enough to explain the general idea of the implementations. (Hint: One of the implementations should be less conservative perhaps using more locks to allow more concurrency.) (c) (3 point) 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? This is a technique called privatization sometimes used to manage contention. (d) ( 2 point) Give one advantage and one disadvantage of this implementation from (c) to the better implementation from (b)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!