C++線程優先級SetThreadPriority的應用實例。本站提示廣大學習愛好者:(C++線程優先級SetThreadPriority的應用實例)文章只能為提供參考,不一定能成為您想要的結果。以下是C++線程優先級SetThreadPriority的應用實例正文
本文實例講述了C++線程優先級SetThreadPriority的應用辦法,分享給年夜家供年夜家參考。詳細辦法以下:
// ThreadPriority.cpp : 界說掌握台運用法式的進口點。
//
#include "stdafx.h"
#include <Windows.h>
DWORD WINAPI ThreadProcIdle(LPVOID lpParameter)
{
for (int i=0;i<20;i++)
{
printf("I'm in thread IDLE...\n");
}
return 0;
}
DWORD WINAPI ThreadProcNormal(LPVOID lpParameter)
{
for (int i=0;i<20;i++)
{
printf("I'm in thread Normal...\n");
}
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwThreadIdIdle;
DWORD dwThreadIdNormal;
HANDLE hThread[2];
//開啟兩個線程
hThread[0] = ::CreateThread(NULL,0, ThreadProcIdle, NULL, CREATE_SUSPENDED, &dwThreadIdIdle);
::SetThreadPriority(hThread[0],THREAD_PRIORITY_IDLE);
::ResumeThread(hThread[0]);
hThread[1] = ::CreateThread(NULL,0, ThreadProcNormal, NULL, CREATE_SUSPENDED, &dwThreadIdNormal);
::SetThreadPriority(hThread[1],THREAD_PRIORITY_NORMAL);
::ResumeThread(hThread[1]);
//期待兩個線程停止
::WaitForMultipleObjects(2,hThread,TRUE,INFINITE);
::CloseHandle(hThread[0]);
::CloseHandle(hThread[1]);
return 0;
}
願望本文所述對年夜家的C++法式設計有所贊助。