lua-users home
lua-l archive

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


Graham Wakefield wrote:

Hi,

I'm having some hard to understand behavior; I create new threads using lua_newthread, and lua_resume them periodically from C++. However, I may wish to at some point terminate a thread before it has completed; I tried calling lua_close() on the thread's lua_State,

You can't call lua_close() on a thread; only on the main state.

> but it seems to
trigger garbage collection prematurely in other threads.

Threads are not garbage collected individually. The garbage collection applies to the entire constellation of threads in a single main state.

I also tried setting the thread to nil in the global environment, but this doesn't trigger collection.

No, it only allows collection. If that is the only reference to the thread, it's resources will be freed during the next garbage collection cycle. You can force a complete garbage collection, if you really need to.

Is there a way to terminate a yielded thread, freeing any resources it was (uniquely) using, whilst leaving other (related) lua states intact?

Not really, other than just removing all references to the thread and waiting for the garbage collector to deal with it.