I need to use Lua in IOCP, and use Thread local Storage to store lua_State *
. I should use lua_close()
destroy the lua_State before the thread destroyed, but the work thread is created by IOCP.
The question is when is the right time to call lua_close
?
static DWORD WINAPI work_thread_proc(void* parameter){
lua_State * L = TlsGetValue(tls_lua_key);
if(NULL = L){
L=luaL_newstate();
//DO some initialze for L...
TlsSetValue(tls_lua_key,L);
}
}
//..... other place call
QueueUserWorkItem(&work_thread_proc, req, WT_EXECUTELONGFUNCTION);