lua-users home
lua-l archive

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


Hi,

Adrian Sietsma wrote:
> Does LuaJIT have a (designed) limit on the number of coroutines it supports ?
> OS - Windows XP

No, but read: jitdoc/coco_portability.html

  Note for Windows: Please read the explanation for the default
  Thread Stack Size
    http://msdn.microsoft.com/library/en-us/dllproc/base/thread_stack_size.asp
  in case you want to create large numbers of Fiber-based coroutines. 

> I get an out of memory error (from Lua) at about the 5,000 coro mark 
> (created, none running).

1MB * 5000 = 5GB (it probably fails earlier)

You need to use a STACKSIZE statement in the .def file.

> collectgarbage reports about 3mb of memory used, before it fails.

The memory for the Fiber stacks is managed by Windows and does
not count towards the Lua memory size.

You should also use the attached interim patch to deallocate
stacks early. This will help reduce memory contention, too.
Yes, a variation of it will be part of the next release.

Bye,
     Mike
--- LuaJIT-1.1.0/src/lcoco.c	2006-03-13 17:30:00.000000000 +0100
+++ LuaJIT-1.1.0-fdel/src/lcoco.c	2006-03-18 12:13:04.000000000 +0100
@@ -81,7 +81,8 @@
 
 #define COCO_JUMPIN(coco) \
   coco->back = GetCurrentFiber(); \
-  SwitchToFiber(coco->fib);
+  SwitchToFiber(coco->fib); \
+  if (L->status != LUA_YIELD) { DeleteFiber(coco->fib); coco->fib = NULL; }
 
 #define COCO_JUMPOUT(coco) \
   SwitchToFiber(coco->back);