question

drjackool-3839 avatar image
0 Votes"
drjackool-3839 asked Castorix31 answered

What is affinity mask for first CPU

Hi
What is affinity mask (SetThreadAffinityMask) for first CPU is 0 or 1?

Thanks

vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Castorix31 avatar image
0 Votes"
Castorix31 answered

You can see this function from MS (D3D11 samples) :

 void CDXUTTimer::LimitThreadAffinityToCurrentProc()
 {
     HANDLE hCurrentProcess = GetCurrentProcess();
    
     // Get the processor affinity mask for this process
     DWORD_PTR dwProcessAffinityMask = 0;
     DWORD_PTR dwSystemAffinityMask = 0;
    
     if( GetProcessAffinityMask( hCurrentProcess, &dwProcessAffinityMask, &dwSystemAffinityMask ) != 0 &&
         dwProcessAffinityMask )
     {
         // Find the lowest processor that our process is allows to run against
         DWORD_PTR dwAffinityMask = ( dwProcessAffinityMask & ( ( ~dwProcessAffinityMask ) + 1 ) );
    
         // Set this as the processor that our thread must always run against
         // This must be a subset of the process affinity mask
         HANDLE hCurrentThread = GetCurrentThread();
         if( INVALID_HANDLE_VALUE != hCurrentThread )
         {
             SetThreadAffinityMask( hCurrentThread, dwAffinityMask );
             CloseHandle( hCurrentThread );
         }
     }
    
     CloseHandle( hCurrentProcess );
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.