Posted 18 November 2013 - 06:37 AM
Hi,
in MP, our admin ask to avoid the "while true do … end" loop in our code, since it consumes server's cpu power. He ask to use triggering like os.pullEvent() etc…
I'm expecting to use the os.Sleep() in that kind of loop so it wont loads the server for nothing. Processing stuff once every 20 ticks is fair enough imo
But in the wiki it says the implementation is like that :
So :
a) Is os.Sleep() making infinte loop loading cpu for nothing ? or
n) Can I safely assert that using os.Sleep() in an infinite loop doesnt load the server's cpu ?
in MP, our admin ask to avoid the "while true do … end" loop in our code, since it consumes server's cpu power. He ask to use triggering like os.pullEvent() etc…
I'm expecting to use the os.Sleep() in that kind of loop so it wont loads the server for nothing. Processing stuff once every 20 ticks is fair enough imo
while true do
sleep(1)
-- get datas
-- process stuff
end
But in the wiki it says the implementation is like that :
function sleep( _nTime )
local timer = os.startTimer( _nTime )
repeat
local sEvent, param = os.pullEvent( "timer" )
until param == timer
end
So :
a) Is os.Sleep() making infinte loop loading cpu for nothing ? or
n) Can I safely assert that using os.Sleep() in an infinite loop doesnt load the server's cpu ?