Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:21:08+00:00 2026-06-12T12:21:08+00:00

I need to pin various c/c++ processes to specific cores on a machine for

  • 0

I need to pin various c/c++ processes to specific cores on a machine for benchmarking only on Windows 7 64-bit. My machine has 16 cores (2×8). I’m trying to do this by calling SetProcessAffinityMask from within the code for a given process. Assuming that’s correct I am unsure of how exactly to use this function. I’ve seen the documentation but am unable to understand its description of what the second argument needs to be. I also haven’t found any example c/c++ usage either on SO or on Google having searched.

Question1: Taking a 16 core machine (2cpux8) for example and a c/c++ project would you please provide an illustrative example for how to use SetProcessAffinityMask to pick each of the 16 cores and an explanation of the second argument for my understanding? How would I translate a core id from 0-15 to its equivalent bitmask?

Question2: Does it make a difference to the usage if there are 2×8 cores as opposed to 16 cores on one cpu? Or is it the same usage?

Many thanks. Here’s what I have so far.

#include <Windows.h>
#include <iostream>

using namespace std;

int main () {

    HANDLE process = GetCurrentProcess();

    DWORD_PTR processAffinityMask = 0; /// What to do here?

    BOOL success = SetProcessAffinityMask(process, processAffinityMask);

    cout << success << endl;

    return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:21:09+00:00Added an answer on June 12, 2026 at 12:21 pm

    The second parameter is a bitmask, where a bit that’s set means the process can run on that proceesor, and a bit that’s clear means it can’t.

    In your case, to have each process run on a separate core you could (for one possibility) pass a command line argument giving each process a number, and use that number inside the process to determine the processor to use:

    #include <Windows.h>
    #include <iostream>
    
    using namespace std;
    
    int main (int argc, char **argv) {
        HANDLE process = GetCurrentProcess();
        DWORD_PTR processAffinityMask = 1 << atoi(argv[1]);
    
        BOOL success = SetProcessAffinityMask(process, processAffinityMask);
    
        cout << success << endl;
        return 0;
    }
    

    Then you’d run this with something like:

    for %c in (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) do test %c
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a program (Java) I'm making I need to check for a specific pin
I have dropdown menu item (pin this site) that i need to hide it
I need to parse this xml. I am trying dom parser. I am not
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Need a map reduce function by mongo in php This my mongo structure [_id]
Need just a push in the right direction with this. I'm building a multi-language
I need to iterate over an array of arbitrary rank. This is for both
I have a MKMapView that has a pin than when pressed shows the annotation's
I'm developing on a mobile gsm platform and I need to know the PIN
In my application i need to obtain user location and this is what i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.