Software Archive
Read-only legacy content
17061 Discussions

Internals of SetThreadPriority Win32 API function

SergeyKostrov
Valued Contributor II
389 Views
*** Internals of SetThreadPriority Win32 API function ***
0 Kudos
6 Replies
SergeyKostrov
Valued Contributor II
389 Views
[ Abstract ] An investigation of internals of Win32 API SetThreadPriority function.
0 Kudos
SergeyKostrov
Valued Contributor II
389 Views
Consider C source codes with Win32 API SetThreadPriority function: ... _RTINLINE RTvoid CrtSetThreadPriority( RTint iThreadPriority ) { #ifdef _RTHRTFUNCTION_TRACEMESSAGE CrtPrintf( RTU("[ CrtSetThreadPriority ]\n") ); #endif BOOL bOK = ::SetThreadPriority( ::GetCurrentThread(), ( RTint )iThreadPriority ); } ...
0 Kudos
SergeyKostrov
Valued Contributor II
389 Views
Here are C source codes with a call to CrtSetThreadPriority function: ... CrtSetThreadPriority( THREADPRIORITY_HIGH ); ...
0 Kudos
SergeyKostrov
Valued Contributor II
389 Views
Here are disassembled codes that show internals how Win32 API SetThreadPriority functionsets a thread priority: ... 00403758 push eax 00403759 call dword ptr ds:[4161B0h] ... ... SetThreadPriority: 7C80C1A8 mov edi, edi 7C80C1AA push ebp 7C80C1AB mov ebp, esp 7C80C1AD mov eax, dword ptr [ebp+0Ch] 7C80C1B0 cmp eax, 0Fh 7C80C1B3 mov dword ptr [ebp+0Ch], eax 7C80C1B6 je AddAtomW+2Fh (7C8330F0h) 7C80C1BC cmp eax, 0FFFFFFF1h 7C80C1BF je SetProcessShutdownParameters+0E7h (7C82E10Ch) 7C80C1C5 push 4 7C80C1C7 lea eax, [ebp+0Ch] 7C80C1CA push eax 7C80C1CB push 3 7C80C1CD push dword ptr [ebp+8] 7C80C1D0 call dword ptr ds:[7C8013B0h] ;; call to NtSetInformationThread 7C80C1D6 test eax, eax 7C80C1D8 jl 7C844901 7C80C1DE xor eax, eax 7C80C1E0 inc eax 7C80C1E1 pop ebp 7C80C1E2 ret 8 7C80C1E5 cmp dword ptr ds:[7C88576Ch], 0 7C80C1EC je 7C82BDC9 7C80C1F2 mov eax, dword ptr ds:[7C88576Ch] 7C80C1F7 jmp GetUserDefaultLCID+6Ah (7C80A01Ah) 7C80C1FC push 0C000000Dh 7C80C201 call GetTickCount+0CFh (7C809419h) 7C80C206 jmp SearchPathW+0F6h (7C80E872h) 7C80C20B nop 7C80C20C nop 7C80C20D nop 7C80C20E nop 7C80C20F nop ... ... NtSetInformationThread: 7C90DCAE mov eax, 0E5h 7C90DCB3 mov edx, 7FFE0300h 7C90DCB8 call dword ptr [edx] ;; call to KiFastSystemCall 7C90DCBA ret 10h 7C90DCBD nop ... ... KiFastSystemCall: 7C90E510 mov edx, esp 7C90E512 sysenter ...
0 Kudos
SergeyKostrov
Valued Contributor II
389 Views
A sysenter instruction executes and control is returned to a next instruction after CS:00403759: ... 00403758 push eax 00403759 call dword ptr ds:[4161B0h] ... The priority of the thread is set.
0 Kudos
SergeyKostrov
Valued Contributor II
389 Views
Latencies of Win32 API SetThreadPriority function are as follows: [ Run-Time testing - Extended Tracing - Yes ] [ Microsoft C++ compiler ] * CRuntimeSet Start * ... [ CrtSetThreadPriority ] - Executed in 2896 clock cycles ... [ CrtSetThreadPriority ] - Executed in 3280 clock cycles ... * CRuntimeSet End * [ Run-Time testing - Extended Tracing - Yes ] [ Borland C++ compiler ] * CRuntimeSet Start * ... [ CrtSetThreadPriority ] - Executed in 28364 clock cycles ... [ CrtSetThreadPriority ] - Executed in 11976 clock cycles ... * CRuntimeSet End * [ Run-Time testing - Extended Tracing - Yes ] [ Intel C++ compiler ] * CRuntimeSet Start * ... [ CrtSetThreadPriority ] - Executed in 2400 clock cycles ... [ CrtSetThreadPriority ] - Executed in 6548 clock cycles ... * CRuntimeSet End * [ Run-Time testing - Extended Tracing - Yes ] [ MinGW C++ compiler ] * CRuntimeSet Start * ... [ CrtSetThreadPriority ] - Executed in 3128 clock cycles ... [ CrtSetThreadPriority ] - Executed in 4284 clock cycles ... * CRuntimeSet End * [ Run-Time testing - Extended Tracing - Yes ] [ Watcom C++ compiler ] * CRuntimeSet Start * ... [ CrtSetThreadPriority ] - Executed in 3776 clock cycles ... [ CrtSetThreadPriority ] - Executed in 4908 clock cycles ... * CRuntimeSet End *
0 Kudos
Reply