TOP Win32API

Simple Thread

void Sleep500(int loop) {
	for(int i=0 ; i<loop ; i++) {
		Sleep(500);
	}
}
HANDLE hThread;
DWORD thread;

// create a thread
hThread=CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Sleep500, (VOID *)1, 0, &thread);

// wait until the thread has finished
while(WaitForSingleObject(hThread, 0)==WAIT_TIMEOUT) {
	Sleep(500);
}

WaitForMultipleObject

TerminateThread

if(hThread != NULL )    TerminateThread(hThread, 0);
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.

SuspendThread(HANDLE)

ResumeThread(HANDLE)

ExitThread(DWORD)

SetThreadPrioroty(HANDLE,int)

管理人/副管理人のみ編集できます