lua-users home
lua-l archive

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


Hi Vijay,

many thanks for your answer!

Vijay Aswadhati wrote:
On Wednesday, August 22, 2007 9:45 AM, Carsten Fuchs wrote:
Well... I was wondering how to best solve the problem. (And if
my assumption above that the thread is never collected is
right?)

If my understanding of Lua is right then I think what you should be
reading about is 'weak table'.

I did, but...

"A weak table can have weak keys, weak values, or both. A table with
weak keys allows the collection of its keys,
but prevents the collection of its values. A table with both weak
keys and weak values allows the collection of
both keys and values. In any case, if either the key or the value is
collected, the whole pair is removed from the
table.

... if I understood the last statement correctly, I think that there still is a problem:
If I have TableInRegistry have weak keys (but normal, i.e. non-weak, values), the key-value pairs can be collected ahead of time, because there are no other references to the keys (which are the "thread" objects that I want to anchor in the first place).

Thinking about it, I'll probably switch to the approach that stores unique Thread-ID numbers as the keys and the thread objects as the values in TableInRegistry, because that solves my original question and solves another problem with not being able to insert new elements into a table while iterating over it using lua_next().

Best regards,
Carsten



--
Ca3D - Engine    http://www.Ca3D-Engine.de
Carsten Fuchs    http://www.Ca3D-Engine.de/c_Carsten.php