Win32 thread priority

Source: Internet
Author: User

SetThreadPriority sets the priority of the specified Thread
[Cpp]
BOOL SetThreadPriority (HANDLE hThread, // handle to the thread
Int nPriority // thread priority level );
Parameter description
Thread handle to be set for hThread
The nPriority priority parameter can be set as the following parameter.
THREAD_PRIORITY_ABOVE_NORMAL has a higher priority than General
THREAD_PRIORITY_BELOW_NORMAL is generally lower
THREAD_PRIORITY_HIGHEST is two levels higher than general (highest)
THREAD_PRIORITY_IDLE idle
THREAD_PRIORITY_LOWEST is 2 lower (lowest)
THREAD_PRIORITY_NORMAL general level
THREAD_PRIORITY_TIME_CRITICAL Real-Time
[Cpp]
# Include <Windows. h>
# Include <iostream>
Using namespace std;
 
Dword winapi ThreadNormal (LPVOID lpParam)
{
Int I = 0;
While (I ++ <10)
Cout <"Normal Thread is running" <endl;
Return 0;
}
 
Dword winapi ThreadAboveNormal (LPVOID lpParam)
{
Int I = 0;
While (I ++ <10)
Cout <"Above Normal Thread is running" <endl;
Return 0;
}
 
Int main ()
{
DWORD dwThreadID;
HANDLE hThread [2];
// Create a abve Normal Thread
HThread [0] = CreateThread (NULL, 0, ThreadAboveNormal, NULL, create_suincluded, & dwThreadID );
// Set priority is abve normal www.2cto.com
SetThreadPriority (hThread [0], THREAD_PRIORITY_ABOVE_NORMAL );
// Resume thread
ResumeThread (hThread [0]);
// Create a Normal Thread
HThread [1] = CreateThread (NULL, 0, ThreadNormal, NULL, 0, & dwThreadID );
// Wait two
WaitForMultipleObjects (2, hThread, TRUE, INFINITE );
// Close thread
CloseHandle (hThread [0]);
CloseHandle (hThread [1]);
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.