lua-users home
lua-l archive

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


I'm thinking my problem is related to allocating memory in one thread
and then trying to deallocate the memory in another thread

Would different threads have separate memory pools?

Yes every OS thread gets its own APR memory pool. Also OS threads never use APR memory pools created in different threads.

However the Lua/APR binding allocates space for a structure using malloc() because this structure (describing the thread's inputs and outputs) needs* to be able to outlive both the parent and child threads / Lua states and it can't be allocated from the child thread's memory pool because this pool is destroyed as soon as the thread exits.

* I'm not actually sure that it is even supposed to be possible for child threads on desktop operating systems to outlive their parent thread, this restriction might simplify my design significantly :-)

Also, are you sure you're not linking the Lua library twice? (Once in the
Lua interpreter and once in your binding)

The Lua/APR makefile used to do this (back when I didn't know any better) but that has since been corrected thanks to Alex Bradbury (who suggested I change this).

Lua 5.2 adds some safety checks to handle those cases.

Okay, if I don't manage to pinpoint the problem soon I'll try an early port to Lua 5.2 to see if that helps me debug this issue.

Thanks for your suggestions!

 - Peter Odding