lua-users home
lua-l archive

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


Hi Steve,

I'm back with your module ;)

As before, I use your winapi module to detect directories/files changes, in a GUI application. From my application, I launch a file_change_thread:

watch_thread, merr = winapi.watch_for_file_changes(
          'my/directory/',
          winapi.FILE_NOTIFY_CHANGE_FILE_NAME+winapi.FILE_NOTIFY_CHANGE_DIR_NAME,
          true,
          print
          )

Then, later, I want to stop it, so I call watch_thread:kill() (I don't know if it is a real good way, but it's the easiest). However, the program freeze during the call to the kill function.

It appears that the module freeze on the call to CloseHandle(lcb->handle) in lcb_free. In the l_Thread_kill function, the lcb_free function is called before TerminateThread(this->thread,1)  and then the module tries to close the 'directory handle' while it is still in use in the running thread and that makes the CloseHandle to freeze. (I would wait from a function such CloseHandle to return an error code in place to freeze, but it appears it has some difficulties in this case).

To fix this, I just moved the call to TerminateThread before the call to lcb_free in the l_Thread_kill function. It seems it works for me, But I don't know if it has some impact on the other uses of your module.

  static int l_Thread_kill(lua_State *L) {
    Thread *this = Thread_arg(L,1);
    BOOL ret = TerminateThread(this->thread,1);
    #line 1164 "winapi.l.c"
    lcb_free(this->lcb);
    return push_bool(L, ret);
  }


Alexandre


---------------------------------------------------------------------
Alexandre Rion
Fuel and Fire Department (MEYGU)
EADS / Airbus Military
---------------------------------------------------------------------