April 2017
Beginner
504 pages
14h 11m
English
We talk about race conditions when the result of a calculation may be different based on the speed and CPU access of the different parallel running threads. Let's take a look at the following two code lines:
void method1(){ 1 a = b; 2 b = a+1; } void method2(){ 3 c = b; 4 b = c+2; }
If the value of b at the start of the execution is 0, and two different threads execute the two methods, then the order of the lines can be 1234, 1324, 1342, 3412, 3142, or 3142. Any execution order of the four lines may happen which assures that 1 runs before 2 and 3 runs before 4, but no other restrictions. The outcome, the value of b, is either 1 or 2 at the end of the execution of the segments, which may not be good and what we wanted ...
Read now
Unlock full access