Your question is Race Conditions in Python. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
How would you handle race conditions in Python?
Implement thread_safe_total(increments), where each list element is the number of times one worker thread must increment a shared counter. Protect the compound read-modify-write operation so the returned total is deterministic.
increments is a list of non-negative integers. Return one integer equal to the sum of all elements after every worker completes.
def thread_safe_total(increments):