2

I am trying to change the affinity of each thread inside the start routine.

Here's the code. In the below code, 't' is the argument passed through the pthread_create function.

    cpu_set_t mask;
    pthread_t c;

    a = *((int *)t);

    printf(" thread no. is %d \n",a);

    CPU_ZERO(&mask);

    a =a/2 + 1;

    CPU_SET(a,&mask);

    c=pthread_self();
    s=pthread_setaffinity_np(c,sizeof(cpu_set_t), &mask);
    if (s!=0)
        handle_error_en(s,"pthread_setaffinity_np");

The thread affinity is not getting changed. Where am I going wrong?

BЈовић
  • 62,405
  • 41
  • 173
  • 273
akhil28288
  • 182
  • 1
  • 2
  • 14

1 Answers1

1

I had misunderstood the bounds of the mask. That was where I was going wrong.

akhil28288
  • 182
  • 1
  • 2
  • 14