pthread-problem

Hi,

I am using a C++ API which doese this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//...
    pthread_attr_t attr;
    pthread_attr_init( &attr ); // returns 0
    pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_JOINABLE ); // returns 0
#ifdef SCHED_RR  // is defined!
    if ( options && (options->flags & RTAUDIO_SCHEDULE_REALTIME) ) {
      struct sched_param param;
      int priority = options->priority;
      int min = sched_get_priority_min( SCHED_RR );
      int max = sched_get_priority_max( SCHED_RR );
      if ( priority < min ) priority = min;
      else if ( priority > max ) priority = max;
      param.sched_priority = priority;
      pthread_attr_setschedparam( &attr, &param );  // returns 22...
      pthread_attr_setschedpolicy( &attr, SCHED_RR );  // returns 0

// test begin:
      int x = pthread_attr_getschedparam( &attr, &param );
      int prio = param.sched_priority;
      printf("\nPriority : %d \n", priority); //  // returns 49
      printf("\ngetsched : %d \n", x); //  // returns 0
      printf("\nT-Priority : %d \n", prio); //  // returns 0
// test end
    }
    else

//... 


I put these lines (test begin to test end) to the code, to see, if thread priority is really working. In the application "priority" is set (here) to 49. This test shows, that it is not working (prio = 0). Is there a mistake in the API or is my test-code wrong?

My second question: If I set process-priority (in the application), how does this value interact with thread priority? For all threads?

Regards
Thomas
Last edited on
You're not checking the return values of those pthread_attr functions. Check if they return errors.

A typical cause of a failure would be not running this test as root or having a restrictive ulimit -r (even as root)
I've checked them now:

 
pthread_attr_setschedparam( &attr, &param );


returns a non zero value (=22). ulimit -r is set to 99. The same as root or as user... I put all return values in my first post.

Even if I set priority to "0" instead of "49" (in the app), it returns the non zero "22".
Last edited on
This is the solution - the missing link:

 
pthread_attr_setschedpolicy(&attr, SCHED_RR);


before (!!!) the line with "pthread_attr_setschedparam( &attr, &param );"

Could anyone tell me something about my second question?
Last edited on
Topic archived. No new replies allowed.