Cuberite Forum
Busy-waiting = ??? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Off Topic (https://forum.cuberite.org/forum-9.html)
+--- Forum: Off Topic Discussion (https://forum.cuberite.org/forum-10.html)
+--- Thread: Busy-waiting = ??? (/thread-220.html)



Busy-waiting = ??? - rs2k - 11-10-2011

From another forum:
Member:
Quote:Would this be ok?

-- os.clock() returns an approximation of the amount of CPU
-- time used by the program, in seconds

function sleep(seconds)
time = os.clock()
while os.clock()-time < seconds do end
end

-- call sleep to sleep for 200 ms
sleep(0.2)


Moderator:
Quote:No. That is not ok. That's called "busy-waiting", and is the programming equivalent of burping into someone else's dinner. It will use 100% of CPU time, spinning wildly, until the wait is over. The sleep() function is in C for a reason: It allows you to wait without taking up all the computer's time doing it.

I LOL'd.


RE: Busy-waiting = ??? - FakeTruth - 11-10-2011

It works thoughTongue