title: Pthread - setting scheduler parameters
body: <p>I wanted to use read-writer locks from pthread library in a way, that writers have priority over readers. I read in my man pages that</p>
  
  <blockquote>
    <p>If the Thread Execution Scheduling option is supported, and the threads involved      in the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR,      the  calling  thread shall not acquire the lock if a writer holds the lock      or if writers of higher or equal priority are blocked on the lock;      otherwise, the calling thread shall acquire the lock.</p>
  </blockquote>
  
  <p>so I wrote small function that sets up thread scheduling options.</p>
  
  <pre><code>void thread_set_up(int _thread)
  {
   struct sched_param *_param=malloc(sizeof (struct sched_param));
   int *c=malloc(sizeof(int));
   *c=sched_get_priority_min(SCHED_FIFO)+1;
   _param-&gt;__sched_priority=*c;
   long *a=malloc(sizeof(long));
   *a=syscall(SYS_gettid);
   int *b=malloc(sizeof(int));
   *b=SCHED_FIFO;
   if (pthread_setschedparam(*a,*b,_param) == -1)
   {
      //depending on which thread calls this functions, few thing can happen
      if (_thread == MAIN_THREAD)
          client_cleanup();
      else if (_thread==ACCEPT_THREAD)
      {
          pthread_kill(params.main_thread_id,SIGINT);
          pthread_exit(NULL);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>sorry for those <code>a,b,c</code> but I tried to <code>malloc</code> everything, still I get <code>SIGSEGV</code> on the call to <code>pthread_setschedparam</code>, I am wondering why?</p>