lua-users home
lua-l archive

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


FYI (to whom it may interest).

While rebuilding native thread features on top of coroutines, I fell on the garbage collection problem: now
that my threads are registered in the scheduler (global object), I needed to find a way to not hold too tight
on them or they will keep on running (if there is a loop) even though they are not reachable from user
code. My scheduled threads are stored in a linked list with weak values:

WeakValue = {__mode='v'}
elem = {
  t  = setmetatable({t = thread}, WeakValue),
}

-- linked list does not loose next elem, even if the thread is gc
-- (thus the double table wrapping).
elem.next = elem

Cheers,

                                                               Gaspard