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

  • Home
  • SEARCH
  • 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 8850205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:50:50+00:00 2026-06-14T12:50:50+00:00

Basically the code below was intended for use on linux and maybe thats the

  • 0

Basically the code below was intended for use on linux and maybe thats the reason I get the error because I’m using windows XP, but I figure that pthreads should work just as well on both machines. I’m using gcc as my compiler and I did link with -lpthread but I got the following error anyways.

|21|undefined reference to sched_setaffinity'|
|30|undefined reference to
sched_setaffinity’|

If there is another method to setting the thread affinity using pthreads (on windows) let me know. I already know all about the windows.h thread affinity functions available but I want to keep things multiplatform. thanks.

#include <stdio.h>
#include <math.h>
#include <sched.h>

double waste_time(long n)
{
    double res = 0;
    long i = 0;
    while(i <n * 200000)
    {
        i++;
        res += sqrt (i);
    }
    return res;
}
int main(int argc, char **argv)
{
    unsigned long mask = 1; /* processor 0 */

/* bind process to processor 0 */
    if (sched_setaffinity(0, sizeof(mask), &mask) <0)//line 21
    {
        perror("sched_setaffinity");
    }

/* waste some time so the work is visible with "top" */
    printf ("result: %f\n", waste_time (2000));

    mask = 2; /* process switches to processor 1 now */
    if (sched_setaffinity(0, sizeof(mask), &mask) <0)//line 30
    {
        perror("sched_setaffinity");
    }

/* waste some more time to see the processor switch */
    printf ("result: %f\n", waste_time (2000));
}
  • 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-14T12:50:51+00:00Added an answer on June 14, 2026 at 12:50 pm

    sched_getaffinity() and sched_setaffinity() are strictly Linux-specific calls. Windows provides its own set of specific Win32 API calls that affect scheduling. See this answer for sample code for Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

basically I'm trying to get #toggle_box to slide down using Jquery, the code below
I am using the code below, its basically babylonian method, how can i modify
I am using a three part code below: First part of the code: Basically
I'm using the code below for my search logic, basically, it evaluates a field
I have tried using the code below to display ImageIcons in JTable. But when
Basically, the code below will generate divs which are then captured using the jquery
Basically this code below returns the right information, but I need to add the
Basically, the code below is what I am using to retrieve images from a
Basically the code below reads in a text file and diplays it on the
My code below won't compile. What am i doing wrong? I'm basically trying to

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.