[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: 90% probability for extra loop in copas.send(), copas.sendto()
- From: Oliver Kroth <oliver.kroth@...>
- Date: Mon, 12 Jan 2015 17:43:41 +0100
Hi,
I am puzzled about a few lines of code in the Copas library functions
copas.send() and copas.sendto():
if (math.random(100) > 90) then
_writing_log[client] = gettime()
coroutine.yield(client, _writing)
end
This takes care that send() will give other coroutines a chance to run,
which is good as otherwise one coroutine may send all the time and no
other can be resumed.
E.g. you have a web server where one coroutine sends a download, while
other coroutines wait for incoming connections; these would be blocked
until the download is finished.
But why is this behaviour coupled to a probabilistic value?
--
Oliver