- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page