← Questions

Two threads updating a shared counter with different stop conditions

0
TeslaCodingLast asked Aug 2026

Start two threads that both update a shared counter. One stops when the counter reaches 10 and returns a snapshot of it; the other stops after one second and returns its snapshot. Print the sum of the two snapshots. Make the updates safe, explain the race you would get without synchronization, and say what output is possible.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding