title: Using available physical CPU core in pthread in Linux
body: <p>I am using Linux Centos.</p>
  
  <p>I am coding in c with pthread and using <strong>pthread_set_affinity</strong>.I want to see each thread to run in unique processor.Like---</p>
  
  <pre><code>thread1 in proccessor 0
  thread2 in proccessor 1
  .
  .
  .
  threadn in processor n
  </code></pre>
  
  <p>currently when i use this set_affinity it runs but when i saw the System-monitor i see that CPU utilization of eight core is not distributed.</p>
  
  <p>CODE is like that
  ::</p>
  
  <pre><code>        if(for thread 1 )
          { 
          pthread_attr_init(&amp;pta);
          CPU_SET(0,&amp;cpuset);
          pthread_setaffinity_np(thread1, sizeof(cpu_set_t), &amp;cpuset);
          pthread_create(&amp;thread1,&amp;pta,&amp;sendimsg,(void*)&amp;message);
          pthread_join(thread1,NULL);
          printf("User for Thread One : %d\n",numb.fir);
          pthread_attr_destroy(&amp;pta);
          CPU_ZERO(&amp;cpuset);
          }  
  
              else if(for thread 2)
              {
              pthread_attr_init(&amp;pra);
              CPU_SET(1,&amp;cpuset1);
              pthread_setaffinity_np(thread2, sizeof(cpu_set_t), &amp;cpuset);
              pthread_create(&amp;thread2,&amp;pra,&amp;sendimsg,(void*)&amp;message);
              pthread_join(thread2,NULL);
              printf("User for Thread Two : %d\n",numb.sec);
              pthread_attr_destroy(&amp;pra);
              CPU_ZERO(&amp;cpuset1);
              }  
  
              for eight thread that way. 
  </code></pre>
  
  <p>Note : thread are assigned distributedly like 20 20 20 20 ...20</p>
  
  <p>the percentage is like that way </p>
  
  <p>10%  1% 0% 2% 0% 1% 0% 0% 1%</p>
  
  <p>I have eight core pc and trying to run 8 thread in 8 core.Is there a way to completly utilize 8 core in this pthread and pthread_set_affinity.</p>