Previously there is a race condition because things happen in this order:
- Check shouldStop
- If shouldStop is false, print the diff
- Call fail() -> set shouldStop
The check and set should really happen in a same critical section.
This patch adds a lock to address the issue.