쓰레드 중지/재시작 ( SuspendThread, ResumeThread ) |
SuspendThread
The SuspendThread function suspends the specified thread.
DWORD SuspendThread( HANDLE hThread // handle to the thread);
Parameters
- hThread
- Handle to the thread.
Windows NT: The handle must have THREAD_SUSPEND_RESUME access.
Return Values
If the function succeeds, the return value is the thread's previous suspend count; otherwise, it is 0xFFFFFFFF. To get extended error information, use the GetLastError function.
ResumeThread
The ResumeThread function decrements a thread's suspend count. When the suspend count is decremented to zero, the execution of the thread is resumed.
DWORD ResumeThread( HANDLE hThread // identifies thread to restart);
Parameters
- hThread
- Specifies a handle for the thread to be restarted.
Windows NT: The handle must have THREAD_SUSPEND_RESUME access to the thread.
Return Values
If the function succeeds, the return value is the thread's previous suspend count.
If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
DWORD WINAPI MyThread( LPVOID arg )
{
int t = 20;
while ( t-- )
{
_tprintf( _T("MyThread()...%d\n"), t);
// Sleep(500);
}
return 0;
}
int _tmain(int argc, TCHAR* argv[])
{
int p = 20;
DWORD idThread;
HANDLE hThread = CreateThread(NULL, 0, MyThread, NULL, CREATE_SUSPENDED, &idThread );
assert( hThread != NULL );
while ( p-- )
{
_tprintf(_T("_tmain()...%d\n"), p);
if ( p == 17 )
{
ResumeThread( hThread );
}
if( p == 10 )
{
SuspendThread( hThread );
}
// Sleep(500);
}
return 0;
}
http://bhnbhn.tistory.com/62
SuspendThread, ResumeThread
'운영체제 & 병렬처리 > Multithread' 카테고리의 다른 글
MFC용 쓰래드 사용법 - MFC MultiThread (Work / UI Thread) (0) | 2012.11.01 |
---|---|
CreateThread 함수 static으로 사용하지 않고 작성하기 (0) | 2012.11.01 |
스레드와 프로세스 그리고 이벤트에대한 정리 (0) | 2012.11.01 |
WaitForSingleObject 함수 (0) | 2012.11.01 |
CreateThread 와 _beginthread, _beginthreadex 의 차이 (0) | 2012.11.01 |