lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 12/01/15 02:43 PM, Oliver Kroth wrote:
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

I believe that is 10%...?
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


--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.