lua-users home
lua-l archive

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


Patrick Donnelly wrote:
> They apparently don't know Lua threads are coroutines and are
> basically harmless for their sandbox needs. :( It sounds like they use
> hooks for bytecode count limits and a custom allocator for memory
> limits.

If you enforce CPU limits by setting debug hooks, coroutines are a problem:

function test ()
  for i = 1,400 do local a = 0 end
end

debug.sethook (function () print "h" end, "", 100)

print ("Same coroutine:")
test()

print ("Another coroutine:")
co = coroutine.create (test)
coroutine.resume (co)


You could solve it by providing an own coroutine.create function that
copies the hook and the remaining count.

Are there other, better alternatives to limit the CPU time?