How to assign a Processor Core for an ATEasy thread or process

Knowledge Base Article # Q200214

Read Prior Article Read Next Article
Summary Assign a Processor Core for an ATEasy thread or process
As multi core processors become more prevalent, software developers can take advantage of the additional performance benefits by writing code that implement multiple threads to accomplish tasks in parallel. ATEasy fully supports multithreading technology and provides a set of API functions that easily allow a user to create, terminate and manage threads.

This article describes two such API function that can be defined in your ATEasy application from the Windows API to manage the processor affinity property of a thread or process. Setting the processor affinity will lock a thread or process into using a particular CPU Core, bypassing the Windows scheduler.

The following describe the function prototypes:

BOOL WINAPI SetProcessAffinityMask( __in  HANDLE hProcess, __in  DWORD_PTR dwProcessAffinityMask)

DWORD_PTR WINAPI SetThreadAffinityMask(__in  HANDLE hThread, __in  DWORD_PTR dwThreadAffinityMask)

These functions are defined in kernel32.dll. In order to use them in ATEasy, kernel32.dll library must be inserted into an ATEasy Program, System, or Driver and the above functions defined.

For each function, the first parameter can be defined as Val AHandle and the second parameter can be defined as Val DWord in ATEasy. The return type can be defined as DWORD.

Pass -1 to the  hProcess parameter to configure the main ATEasy process.

Pass the return value from the ATEasy functions CreateThread or GetCurrentThread to hThread to configure a specific thread.

dwProcessAffinityMask and dwThreadAffinityMask are bit-wise masks that indicate which core will be selected.

More information can be found at the following links:
Article Date 4/7/2011 9:01:29 AM     Updated: 4/12/2011 2:24:42 PM
Keywords Processor Affinity, MultiCore, Core, CPU, ATEasy, Threads, Threading, Thread, Process

0 ratings | 0 out of 5
Read Prior Article Read Next Article