lua-users home
lua-l archive

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


Hi,

You did not mention if you are  using the lua_lock and lua_unlock macros
to enable concurrent access to Lua  internal structures, but you seem to
be using a single  Lua thread and this might work.  Anyways, take a look
at the documentation for the function you are calling:

    TerminateThread is a dangerous function that should only be used in the
    most extreme cases. You should call TerminateThread  only if you know
    exactly what the target thread is doing, and you control all of the code
    that the target thread could possibly be running at the time of the
    termination. For example, TerminateThread can result in the following
    problems:

        * If the target thread owns a critical section, the critical section
          will not be released.
        * If the target thread is allocating memory from the heap, the heap
          lock will not be released.
        * If the target thread is executing certain kernel32 calls when it is
          terminated, the kernel32 state for the thread's process could be
          inconsistent.
        * If the target thread is manipulating the global state of a shared
          DLL, the state of the DLL could be destroyed, affecting other users
          of the DLL.

You  can't be  sure  if Lua  is  allocating memory  when  you call  this
function.  Therefore,  at  least  on  the  second  item,  you  could  be
dead-locking (CloseHandle will probably try to acquire the heap lock).

I  am not  sure if  this is  your problem,  but you  should avoid  using
TerminateThread  at all  cost.  There are  cleaner ways  to  stop a  Lua
program. Try setting  a line hook (this issue has  been discussed here a
few messages ago).

Regards,
Diego.