SetThreadAffinityMask not working

daniel02x 26 Reputation points
2022-11-27T18:23:32.727+00:00

hello im trying read RDTSC as system timer to do so i read it in first core
SetThreadAffinityMask(GetCurrentThread,1); but its dont work so the alternative is start it with /affinity 1 and thats work how its possible?

start /affinity 1 myrdtsc.exe

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
Windows 10 Compatibility
Windows 10 Compatibility
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Compatibility: The extent to which hardware or software adheres to an accepted standard.
455 questions
{count} votes

1 answer

Sort by: Most helpful
  1. daniel02x 26 Reputation points
    2022-12-01T01:55:35.07+00:00

    THREAD_ALL_ACCESS also fix that :)

       quint64 threadId = (quint64)QThread::currentThreadId();  
      
         
        HANDLE handle = OpenThread(THREAD_ALL_ACCESS, false, threadId);  
      
        SetThreadAffinityMask(handle, 0x01);  
    

    https://blog.csdn.net/zyhse/article/details/107593563

    1 person found this answer helpful.
    0 comments No comments