- 注册时间
- 2021-4-16
- 最后登录
- 2024-7-10
- 在线时间
- 5 小时
编程入门
- 龙马币
- 93
|
设置线程优化级SetThreadPriority调用方法
- #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;
- }
复制代码
|
|