Pthread - setting scheduler parameters
Posted
by
Andna
on Stack Overflow
See other posts from Stack Overflow
or by Andna
Published on 2012-06-08T21:53:45Z
Indexed on
2012/06/09
4:40 UTC
Read the original article
Hit count: 146
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
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.
so I wrote small function that sets up thread scheduling options.
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->__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);
}
}
}
sorry for those a,b,c
but I tried to malloc
everything, still I get SIGSEGV
on the call to pthread_setschedparam
, I am wondering why?
© Stack Overflow or respective owner