AW: POSIX scheduling and priority question

Joel Sherrill joel.sherrill at OARcorp.com
Tue Apr 22 14:41:31 UTC 2014


On 4/22/2014 9:39 AM, Gempeler Stefan wrote:
> Hi Sebastian, thanks for your fast reply. Using PTHREAD_EXPLICIT_SCHED seems to solve the problem.
I was writing a reply when Sebastian's showed up. Glad it was right. :)

As a final throw in, passing NULL as the attributes to pthread_create()
uses the implementation's default attribute set. POSIX does not specify
what that is. So when you use NULL there, all bets are off for portable
behavior.

If you don't mind, could you clean up the entire example and provide
a README? If you are willing and make the code BSD or "as is" type
license, it would be good to put in examples-v2/posix.
> For the sake of completeness
> ************************************************************************************
>
> 	printk( "\n\n========= STARTING ============  %s, %s\n", __DATE__, __TIME__);
>
> 	// start the waiting task, highest priority
> 	test_param.sched_priority = sched_get_priority_max( SCHEDULER_POLICY );
> 	pthread_attr_setschedparam( &test_attr, &test_param );
> 	pthread_attr_setinheritsched( &test_attr, PTHREAD_EXPLICIT_SCHED );
> 	pthread_create( &thread_wait,	&test_attr,	test_wait_thread,	0 );
>
> 	// start the full running task, lowest priority
> 	test_param.sched_priority = sched_get_priority_min( SCHEDULER_POLICY );
> 	pthread_attr_setschedparam( &test_attr, &test_param );
> 	pthread_attr_setinheritsched( &test_attr, PTHREAD_EXPLICIT_SCHED );
> 	pthread_create( &thread_full,	&test_attr,	test_full_thread,	0 );
>
> ************************************************************************************
>
> Kind regards 
> Stefan
>
>
> -----Ursprüngliche Nachricht-----
> Von: Sebastian Huber [mailto:sebastian.huber at embedded-brains.de] 
> Gesendet: Dienstag, 22. April 2014 15:33
> An: Gempeler Stefan
> Cc: rtems-users at rtems.org
> Betreff: Re: POSIX scheduling and priority question
>
> On 2014-04-22 14:53, Gempeler Stefan wrote:
> [...]
>> void *POSIX_Init( void *argument )
>>
>> {
>>
>> #define SCHEDULER_POLICY                     (SCHED_RR)
>>
>>                  pthread_t           thread_full;
>>
>>                  pthread_t           thread_wait;
>>
>>                  pthread_attr_t                test_attr;
>>
>>                  struct sched_param       test_param;
>>
>>                  assert( sem_init( &test_semaphore, 0, 0 )==0 );
> This is very dangerous since #define NDEBUG will wipe out this function call.
>
>>                  // get default attributes
>>
>>                  pthread_attr_init( &test_attr );
>>
>>                  // store parameters
>>
>>                  pthread_attr_getschedparam( &test_attr, &test_param 
>> );
>>
>>                  // set policy
>>
>>                  pthread_attr_setschedpolicy( &test_attr, 
>> SCHEDULER_POLICY );
>>
>>                  printk( "\n\n========= STARTING ============  \n" );
>>
>>                  // start the waiting task, highest priority
>>
>>                  test_param.sched_priority = sched_get_priority_max( 
>> SCHEDULER_POLICY );
>>
>>                  assert( pthread_attr_setschedparam( &test_attr, 
>> &test_param
>> )==0 );
> See also PTHREAD_INHERIT_SCHED vs. PTHREAD_EXPLICIT_SCHED.
>
>>                  pthread_create( &thread_wait,              &test_attr,
>> test_wait_thread,          0 );
> [...]
>
> --
> Sebastian Huber, embedded brains GmbH
>
> Address : Dornierstr. 4, D-82178 Puchheim, Germany
> Phone   : +49 89 189 47 41-16
> Fax     : +49 89 189 47 41-09
> E-Mail  : sebastian.huber at embedded-brains.de
> PGP     : Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>
>
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-users

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985




More information about the users mailing list