This article describes the use of C + + thread priority SetThreadPriority, shared for everyone to reference. The specific methods are as follows:
Copy Code code as follows:
ThreadPriority.cpp: Defines the entry point for a console application.
//
#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];
Open two threads
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]);
Waiting for two threads to end
:: WaitForMultipleObjects (2,hthread,true,infinite);
:: CloseHandle (hthread[0]);
:: CloseHandle (hthread[1]);
return 0;
}
I hope this article will help you with the C + + program design.