Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
12748 Discussions

Posix thread priority and scheduling..

Altera_Forum
Honored Contributor II
1,320 Views

I would like to create 4 threads, with the following attributes 

 

SCHED_FIFO 

thread 1 has priority value of 99 

thread 2 of 99 

thread 3 of 50 

thread 4 of 20 

 

(where the higher the number, the higher the priority. thus higher priority thread should preempt lower priority thread) 

 

So I wrote this code: 

 

   pthread_attr_t thread_attribute;    pthread_t      thread_id;    struct sched_param thread_param;        thread_param.sched_priority = 40;        printf("priority %d\n", thread_param.sched_priority);        pthread_attr_init( &thread_attribute );    pthread_attr_setdetachstate( &thread_attribute, PTHREAD_CREATE_DETACHED );    pthread_attr_setschedpolicy( &thread_attribute, SCHED_FIFO );    pthread_attr_setschedparam(  &thread_attribute, &thread_param );    printf("current prio: %d\n", pthread_attr_getschedparam(  &thread_attribute, &thread_param ));    sched_setscheduler( 0, SCHED_FIFO, &thread_param );    printf("current prio: %d\n", pthread_attr_getschedparam(  &thread_attribute, &thread_param )); 

 

What I see on the screen is the prority value is 0 and 0. Am I setting the thread priority value the right way? Has anyone been able to change the scheduling policy and thread's priority?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
376 Views

Hi ShaChris23, 

 

> printf("current prio: %d\n", pthread_attr_getschedparam( &thread_attribute, &thread_param )); 

 

pthread_attr_getschedparam doesn't return the _priority_, it returns zero on success, non-zero 

otherwise. You need to look at the returned thread_param. 

 

Regards, 

--Scott
0 Kudos
Reply