Two threads updating a shared counter with different stop conditions
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.
No answer yet. Write the first one; the best answer gets endorsed.
