Variable not updated
-
Hello, I have a code which checks some variable which has to be changed from false to true in other class, but, even if it changes it does not appears. More details, I have the code:
ms.isDataReady = false;
...
while(!ms.isDataReady);the loop while waits forever in my main method even if
ms.isDataReady
becomes true in
ms
's appropriate method. What I should do?
-
Hello, I have a code which checks some variable which has to be changed from false to true in other class, but, even if it changes it does not appears. More details, I have the code:
ms.isDataReady = false;
...
while(!ms.isDataReady);the loop while waits forever in my main method even if
ms.isDataReady
becomes true in
ms
's appropriate method. What I should do?
-
It changes somewhere else but it doesn't affects the change in while in other words it doesn't appears changed, unless I use a tricky solution so instead of
while(!ms.isDataReady);
I put
while(!ms.isDataReady) Thread.sleep(1);
-
It changes somewhere else but it doesn't affects the change in while in other words it doesn't appears changed, unless I use a tricky solution so instead of
while(!ms.isDataReady);
I put
while(!ms.isDataReady) Thread.sleep(1);
-
Your
while
statement is not the best way to wait for something to happen, as it will just lock the processor, spinning on that statement.Veni, vidi, abiit domum
What do you suggest instead ... ?
-
What do you suggest instead ... ?
-
Well that depends on what you are trying to do. What is the interaction between these two threads and what is the first one waiting for?
Veni, vidi, abiit domum
Here are the details of the problem: I have a class MISPSerial (instance named ms) which deals for stream of bytes to arrive via serial port. In my class which contains the main method I wait for the variable (ms.isDataReady) in MISPSerial which tells that the stream is received completely. So my main method waits for the stream to be received and then continues with instructions that follow. What would you suggest?
-
Here are the details of the problem: I have a class MISPSerial (instance named ms) which deals for stream of bytes to arrive via serial port. In my class which contains the main method I wait for the variable (ms.isDataReady) in MISPSerial which tells that the stream is received completely. So my main method waits for the stream to be received and then continues with instructions that follow. What would you suggest?