deadlock - incrementing and decrementing shared variable at same time -


if x initialized 0 before of happens, possible values of x after following 2 loops executed concurrently in 2 different processes? (one in each process)

for (i = 0; < 5; i++)     x++  (j = 0; j < 5; j++)     x-- 

(edited)what can happen here? can instructions fail, or result x = 0?

there no reason why should have deadlock since there no locking code. different values of , j depend on non-deterministic order of thread execution. first thread starts, stops time i=4, second thread starts, initializes 0 , proceeds until end of first , second loop. second thread resumes , exits first loop i=6 (value left previous thread), proceeds in second loop. 1 scenario. can come similar ones , possibilities endless.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -