1
$\begingroup$

if there is a better stack exchange suited for this question please inform me.

say you have a thread that is constantly checking the state of a variable in 2 ms intervals

volatile int var = 0;
while(true){ 
if(var == 1) 
   break;
Sleep(2);
}

you have another thread thats overwriting this variable to 1 in an external process/thread but setting it back to 0 once its complete with its process and this process takes 1 ms.

if this second thread never gets interrupted in anyway (like with an APC) will the first thread ever catch the second thread modifying this variable?

if the cpu only has 1 thread this would be impossible, but on a processor with multiple parallel threads is this likely?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.