title: confused about theads schedule of SCHED_FIFO policy when threads have same priority
body: <p>　　I created two threads ThreadA and ThreadB in main thread, and three threads   have the same Priority. the order of call is ThreadA in front of ThreadB(I can't understand).<br>
  　　However, the order of call is ThreadB in front of ThreadA when increasing the priority main thread(I understanded).
  I get this message from man page as follows:
  <code>
    A call to sched_setscheduler(2), sched_setparam(2), or sched_setattr(2)
    will  put  the SCHED_FIFO (or SCHED_RR) thread identified by pid at the
    start of the list if it was runnable.  As a consequence, it may preempt
    the  currently  running  thread  if it has the same priority.  (POSIX.1
    specifies that the thread should go to the end of the list.)
  </code></p>
  
  <p>Code as follows:</p>
  
  <pre><code>/*
   * critical.c
   *
   * compile with  gcc critical.c -o critical -lrt -lpthread
   *
   *  result is aaaaabbbbb when three thread have same priority 
   *  result is bbbbbaaaaa when main thread has higher priority 
   */
  
  #include &lt;pthread.h&gt;    /* header file for pthreads */
  #include &lt;unistd.h&gt;     /* header file for POSIX conformance */
  #include &lt;time.h&gt;       /* header file for POSIX time management */
  #include &lt;sched.h&gt;      /* header file for POSIX scheduling */
  #include &lt;stdio.h&gt;      /* header file for standard input/outputlibrary */
  #define _REENTRANT      /* macro to ensure system calls are reentrant */
  
  void *threadA(void *);   /* predefine threadA routine */
  void *threadB(void *);   /* predefine threadB routine */
  
  pthread_t threadA_id,threadB_id,main_id;   /* thread identifiers */
  pthread_attr_t attrA,attrB;        /* thread attribute structures */
  struct sched_param param;          /* scheduling structure for thread attributes */
  
  int policy=SCHED_FIFO;
  int priority_min,priority_max;     /* for range of priority levels */
  
  /* main routine */
  int main()
  {
    struct timespec start;
    int status;                        /* check that system calls return ok */
  
    clock_gettime(CLOCK_REALTIME, &amp;start);        /* get the time   */
    printf("Start time is: %d seconds %d nano_seconds\n",start.tv_sec,start.tv_nsec);
  
    /* Set processor affinity */
    unsigned long mask = 1; /* use only 1 CPU core */
    unsigned int len = sizeof(mask);
    status = sched_setaffinity(0, len, &amp;mask);
    if (status &lt; 0) perror("sched_setaffinity");
    status = sched_getaffinity(0, len, &amp;mask);
    if (status &lt; 0) perror("sched_getaffinity");
  
    /* Find priority limits */
  
    priority_max = sched_get_priority_max(policy);
    priority_min = sched_get_priority_min(policy);
  
    /* Change priority and policy of main thread */
  
    main_id = pthread_self();
    param.sched_priority=priority_min;
    status = pthread_setschedparam(main_id, policy, &amp;param);
    if (status != 0) perror("pthread_setschedparam"); /* error check */
  
    /* Create threadA */
  
    param.sched_priority = priority_min;
    pthread_attr_init(&amp;attrA);
    status = pthread_attr_setschedpolicy(&amp;attrA,policy);
    if (status != 0) perror("pthread_attr_setschedpolicy"); /* error check */
    status = pthread_attr_setschedparam(&amp;attrA,&amp;param);
    if (status != 0) perror("pthread_attr_setschedparam"); /* error check */
    status = pthread_create(&amp;threadA_id, &amp;attrA, threadA, NULL);
    if (status != 0) perror("pthread_create"); /* error check */
    status = pthread_setschedparam(threadA_id,policy,&amp;param);
    if (status != 0) perror("pthread_setschedparam");
  
    /* Create threadB */
    param.sched_priority = priority_min; /* so that B runs with a higher priority than A */
    pthread_attr_init(&amp;attrB);
    status = pthread_attr_setschedpolicy(&amp;attrB,policy);
    if (status != 0) perror("pthread_attr_setschedpolicy"); /* error check */
    status = pthread_attr_setschedparam(&amp;attrB,&amp;param);
    if (status != 0) perror("pthread_attr_setschedparam"); /* error check */
    status = pthread_create(&amp;threadB_id, &amp;attrB, threadB, NULL);
    if (status != 0) perror("pthread_create"); /* error check */
    status = pthread_setschedparam(threadB_id,policy,&amp;param);
    if (status != 0) perror("pthread_setschedparam");
  
    /* Join threads - force main to wait for the thread to terminate */
    printf("main() waiting for threads\n");
  
    status = pthread_join(threadA_id, NULL);
    if (status != 0) perror("pthread_join(threadA_id, NULL)"); /* error check */
    status = pthread_join(threadB_id, NULL);
    if (status != 0) perror("pthread_join(threadB_id, NULL)"); /* error check */
  
    printf("\nmain() reporting that all threads have terminated\n");
    return(0);
  
  }  /* end of main */
  
  void *threadA(void *arg)
  {
    int j;
    for(j=1;j&lt;=5;j++){
      printf("a");                    
    }
    return (NULL);
  }
  
  void *threadB(void *arg)
  {
    int j;
    for(j=1;j&lt;=5;j++){
      printf("b");                     
    }
    return (NULL);
  }
  </code></pre>