I am not sure about the term I used but what I'm thinking about is something like this. I want to have a loop which will continue to loop until a certain variable, say a boolean becomes change.
Code:
while( locked ){
// nothing
}
Then on another part of the code, on perhaps a thread, it will set locked to false so the code will break free from the loop and continue on. But I seem to notice that it eats up a lot of processing power, so I set up sleep for a few milliseconds, like in Java:
Code:
while(locked ){
try{
Thread.currentThread().sleep(100);
}
catch( InterruptedException e ){
}
}
I was wondering if there's a better way of implementing something like this in Java. Something that is much more punctual than a given amount of time (in that example, 100ms) and something that doesn't consume as much computer processing power. And maybe also something for C because I'm curious. Thanks a lot.