lua-users home
lua-l archive

Terminating threads

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


Hello,
I have a big problem since many weeks.
I have two threads.The first wait for an event to stop the execution 
et the second is a test.
I want stop my test thread when the operator want (Urgence Stop) but 
with my program there is a BIG problem because I think LUA doesn't 
stop correctly so all is blocked.
This is my program :
/*********************Test*****************************/
DWORD WINAPI C_SoftFunc(lua_State *L) {
	int i =1;
	threadId[1] = GetCurrentThreadId(); 
 lua_dofile(L, "factorial.lua");
	return 0;
}
/****************Thread alertable**********************/
DWORD WINAPI interrupted(lua_State *L){
	DWORD stop;
	threadId[2] = GetCurrentThreadId();
	while(!kbhit()){
		stop = WaitForSingleObject(hthread[1],1);
		if (stop == WAIT_OBJECT_0){
			return 0;
		}
	}
	_getch();
 	printf("INTERRUPTED!\n");
	TerminateThread(hthread[1],threadId[1]);
	return 0;
}
/**********************LUA_APP*************************/
int debutThread(lua_State *L){
	hthread[1] = CreateThread(NULL,0,C_SoftFunc,L,0,&threadId[1]);
	hthread[2] = CreateThread(NULL,0,interrupted,L,0,&threadI[2]);
	WaitForSingleObject(hthread[1],INFINITE);
	CloseHandle(hthread[1]);
	CloseHandle(hthread[2]);
	return 0;
}
/*****************Correspondance avec LUA**********************/
void lua_initdll( lua_State *L ) {
	lua_register(L, "Thread",debutThread);
}
HELP ME PLEASE.
Thank you.
Christine. 

AltStyle によって変換されたページ (->オリジナル) /