c - Issue with pthread_setschedparam, system hangs -
static int pthrd_setthread_prio(int thred_prio) { int thrd_policy = sched_rr; struct sched_param thr_prio; int res=0; thr_prio.sched_priority = thred_prio; /* try setting thread/process priority via pthread */ res = pthread_setschedparam( pthread_self(), thrd_policy, (const struct sched_param*) &thr_prio); //pthread_setschedparam has 2 return values 0 on successs, >0 on failure if(res != 0) { deb_err("pthread_setschedparam failed withe error %d\n",res); } res = pthread_getschedparam( pthread_self(), &thrd_policy, &thr_prio); if(res < 0) { deb_err("pthread_getschedparam failed\n"); } printf("thread policy %s priority %d process id %ld\n", \ ( (thrd_policy == sched_fifo) ? "sched_fifo" : (thrd_policy == sched_rr) ? "sched_rr" : (thrd_policy == sched_other) ? "sched_other" : "???"), thr_prio.sched_priority, syscall(sys_gettid)); if ( (thr_prio.sched_priority != thred_prio) || (thrd_policy != sched_rr) ) { deb_err("thread priority == %d, should %d error! using pthread\n",thr_prio.sched_priority ,thred_prio); res=-1; } return (res); } with above code used setting thread priority , creating thread-2 causing system hang @ point.
i established telnet session , used "ps -ef" command check real time priority of thread-2 , see set correctly. @ later stage causing system hang. confirmed removing particular function , assigned default priority thread.
could please let me know if missing here ?
you're setting realtime scheduling policy on thread. means higher priority realtime tasks can preempt it, if thread enters endless (or very-long-running) loop consuming cpu , not blocking, starve out other non-realtime tasks.
calculation-heavy threads don't block should not given realtime scheduling policy.
Comments
Post a Comment