December 2018
Beginner to intermediate
796 pages
19h 54m
English
Thread A reads the value (1), posts it to the API, increments it to 2, but before it can save it back, the scheduler decides to pause thread A in favor of Thread B.
Thread B reads the value (still 1!), posts it to the API, increments it to 2, and saves it back. The scheduler then switches over to Thread A again. Thread A resumes its stream of work by simply saving the value it was holding after incrementing, which is 2.
After this scenario, even though the operation has happened twice as in Scenario A, the value saved is 2, and the API has been called twice with 1.
In a real-life situation, with multiple threads and real code performing several operations, the overall behavior of the program explodes ...
Read now
Unlock full access