lua-users home
lua-l archive

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


Roberto Ierusalimschy wrote:
> 
> But there is still a long way to define the best API to support
> different implementations and coroutine "styles" (and, of course, to easy
> the task of those implementing real multi-thread in the language).

My current plans: a new type TAG_COROUTINE (or how types will be named
in 4.0).  Data of this type will be the the thread specific data of
lua_state + a user field for the C coroutine handle.  The lua_state
only has a reference to the currently active coroutine instead of the
thread specific data.

The C API will be 3 functions:

  handle = cocreate(cfunc, stacksize),
  void *data = cocall(handle, void *data)
  codelete(handle)

The Lua API will be even simpler:
  a global: _COROUTINE_STACKSIZE  (C stack size)
  maybe globals: cocurrent, comain.  will see.
  coro = cocreate(func)

Calling coroutines is simply done by calling them:

  a,b,c = coro(x,y,z)  -- the vars are passed/received arguments.

Delete is done by the garbage collector.


But I guess, 4.1 will take a while.  So you'll see my implementation *g*

Ciao, ET.


PS: What do you mean with "real mutli-thread"?  Real concurrent pre-
emptive threads?  That would be hell...