$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #193

Which fix removes the bug?

import threading
count = 0
def bump():
    global count
    count += 1
  1. Guard it with a Lock
  2. Make count a float
  3. Use a nested function
  4. Declare count nonlocal
+= is a read, add and write; two threads can interleave and lose an increment.
Play Problem Solving ▸