Can it be done?
Background:
As we all know, there are a gajillion ways of inserting delay into a program, from superfluous for loops that do nothing, to the more sophisticated time(NULL)-split>howLong method, and then there are nonportables such as windows.h's Sleep(), and the myriad of sleep()'s, delay()'s and _delay()'s found in compilers.
My question:
Is there any way to make a portable, nonbusy hold?
My current code does this:
Which is a portable(mostly) but busy wait. I think windows.h's Sleep() is nonbusy, but it isn't portable.Code:void holdOnThere(int howLongToWait) { time_t split = time(NULL); while (time(NULL) - split < howLongToWait) { } return; }
Is there any way to get both in one construct, and if so, how?



LinkBack URL
About LinkBacks


