Steve Luke wrote:What kind of critique do you want?
If you just want critique on the strategy we need to know a bit more about the use-case. Can the value to be returned ever be invalid once a valid value has been retrieved? Or is the local - cached value good until a new value comes along?
Steve Luke wrote:
It is really impossible to talk about the logic if we don't know how it is used. It might be right, near right, or completely off. Please provide a more real-world explanation than "The server updates ClassB and ClassA must wait for a new value".
Arun Bommannavar wrote:Sometimes, when Plot class tries to read Motor value and the code gets stuck in "while(!valid)" loop because first time value hasnt been read yet. Even when the value is read and it sets valid = true, the code is still stuck in "while(!valid)" loop. This I found out by print statements. I tried declaring valid as volatile but it doesnt help. In the following code, I changed wait() to wait(20) and then printed the value for valid, it still printed false. So I am not sure why it gets stuck in the while(!valid) loop.