One-day training of Windows APIs (49) setthreadpriority and getthreadpriority Functions

Source: Internet
Author: User
One-day training of Windows APIs (49) setthreadpriority and getthreadpriority Functions

Windows is the operating system for preemptive task execution. Both processes and threads have a priority to select the execution mode, which makes it easier for users to process multiple tasks. For example, when you listen to music while surfing the Internet, you can execute music tasks to a higher level, so that music does not sound intermittent. When you write a network program, a thread receives data from the network, and a thread writes data to the hard disk, you can set the priority of the network receiving thread to a higher level, this is because you can write the received data to the memory, cache it, and write it to the hard disk. Another type of task is to set the thread priority when the program you write needs to be executed in idle time. In this way, the setthreadpriority and getthreadpriority functions are used to set the thread priority and obtain the thread priority.

The setthreadpriority and getthreadpriority functions are declared as follows:
Bool
Winapi
Setthreadpriority (
_ In handle hthread,
_ In int npriority
);
Hthread is the thread handle.
Npriority is the priority of the thread.


Winbaseapi
Int
Winapi
Getthreadpriority (
_ In handle hthread
);
Hthread is the thread handle.
The returned value is the priority of the thread.

An example of calling a function is as follows:
#001 // set the thread priority and obtain the thread priority.
#002 // Cai junsheng 2007/10/11 QQ: 9073204 Shenzhen
#003 void threadpriority (void)
#004 {
#005 //
#006: setthreadpriority (m_hthread, thread_priority_highest );
#007
#008 //
#009 if (: getthreadpriority (m_hthread) = thread_priority_highest)
#010 {
#011 //
#012 outputdebugstring (_ T ("thread_priority_highest/R/N "));
#013}
#014
#015}

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.