title: What does pthread_attr_setinheritsched exactly do?
body: <p>I'm working on a school problem. I don't want the answer to the problem, but I do have a question.</p>
  <p>I'm working on POSIX threads, I have 4 tasks, and I need to run task 3 and 4 before task 1 and 2, by using priority.</p>
  <p>Before he wen't on his holiday, my teacher gave me a bunch of example code, which I'm trying to figure out. Especially the line <code>pthread_attr_setinheritsched(&amp;tattr1,PTHREAD_EXPLICIT_SCHED);</code>. I can't figure out what it does. I do know that if I delete it, all threads will run without checking their priority. If I don't delete it, the threads won't run at all. So it's a bit finicky to debug.</p>
  <p>I provided the full code below (except for the tasks). Can someone explain what that line does precisely?</p>
  <pre class="lang-c prettyprint-override"><code>int main() {
      // everything on core 0
      cpu_set_t mask;
      CPU_ZERO(&amp;mask);
      CPU_SET(0, &amp;mask);
      sched_setaffinity(0, sizeof(mask), &amp;mask);
      
      // attr1
      pthread_attr_t tattr1;
      struct sched_param param1;
      pthread_attr_init(&amp;tattr1);
      pthread_attr_setschedpolicy(&amp;tattr1,SCHED_RR);
      pthread_attr_getschedparam(&amp;tattr1,&amp;param1);
      param1.sched_priority=10;
      pthread_attr_setinheritsched(&amp;tattr1,PTHREAD_EXPLICIT_SCHED); // &lt;---- THIS LINE
      pthread_attr_setschedparam(&amp;tattr1,&amp;param1);
      
      // attr2
      pthread_attr_t tattr2;
      struct sched_param param2;
      pthread_attr_init(&amp;tattr2);
      pthread_attr_setschedpolicy(&amp;tattr2,SCHED_RR);
      pthread_attr_getschedparam(&amp;tattr2,&amp;param2);
      param2.sched_priority=0;
      pthread_attr_setinheritsched(&amp;tattr2,PTHREAD_EXPLICIT_SCHED); // &lt;---- THIS LINE
      pthread_attr_setschedparam(&amp;tattr2,&amp;param2);
      
      // spin up threads
      pthread_t tid_1;
      pthread_create(&amp;tid_1, &amp;tattr1, taskOne, NULL);
      pthread_t tid_2;
      pthread_create(&amp;tid_2, &amp;tattr1, taskTwo, NULL);
      pthread_t tid_3;
      pthread_create(&amp;tid_3, &amp;tattr2, taskThree, NULL);
      pthread_t tid_4;
      pthread_create(&amp;tid_4, &amp;tattr2, taskFour, NULL);
      
      pthread_join(tid_1, NULL);
      pthread_join(tid_2, NULL);
      pthread_join(tid_3, NULL);
      pthread_join(tid_4, NULL);
  }
  </code></pre>