lua-users home
lua-l archive

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


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)

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?