Why second thread doesn't preempt the first one?

Joel Sherrill <joel@OARcorp.com> joel.sherrill at OARcorp.com
Mon May 9 16:01:57 UTC 2005



Alex wrote:
> Hi,
> 
> I am trying to use the SCHED_FIFO and I am making some POSIX test programs
> but the second extra thread never preempts the execution of the first on, 
> even with a bigger priority.
> The bkgrnd thread starts to execute and only when the bkgrnd thread finish
> the worker thread starts to execute.
> 
> What I want is to see the second thread preempting the first. I want to use the FIFO algorithm in conjunction with the preemptation capability.
> 
> What am I making wrong?

Two guesses.

(1) POSIX thread priorities run opposite of the Classic API.  1 is a low 
priority and 120 is a high priority.  So your background thread has the
higher priority.

(2) Do you have a clock tick configured in your test case?

--joel


> Many thanks
> 
> Alex
> 
> 
> This is the pseudo-code:
> 
> main:
>   rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK,NULL); 
> 
>   pthread_attr_init(Attribs_for_thread_1)
>   pthread_attr_init(Attribs_for_thread_2)
> 
>   pthread_attr_setschedpolicy(&Attribs_for_thread_1, SCHED_FIFO); 
>   pthread_attr_setschedpolicy(&Attribs_for_thread_2, SCHED_FIFO);
> 
>   SchedParams_for_thread_1.sched_priority = 120;
>   SchedParams_for_thread_2.sched_priority = 1;
> 
>   pthread_attr_setinheritsched(&Attribs_for_thread_1,PTHREAD_EXPLICIT_SCHED)
>   pthread_attr_setinheritsched(&Attribs_for_thread_2,PTHREAD_EXPLICIT_SCHED)
> 
>   pthread_attr_setschedparam(&Attribs_for_thread_1, &SchedParams_for_thread_1)
>   pthread_attr_setschedparam(&Attribs_for_thread_2, &SchedParams_for_thread_2)
> 
>   pthread_create(&Task_id1, &Attribs_for_thread_1,Task_Bkgrd, NULL);
>   sleep(1);
>   pthread_create(&Task_id2, &Attribs_for_thread_2,Task_worker, NULL);
> 
> 
> 
> Task_Bkgrd:
>   rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK,NULL);
>   printk("Beginning bkgrd thread");
>   "Huge calculation that taks almost 1 minute"
>   printk("End of bkgrd thread"); 
> 
> 
> 
> Task_worker
>   rtems_task_mode (RTEMS_PREEMPT, RTEMS_PREEMPT_MASK,NULL);
>   printk("Beginning worker thread");
>   "Huge calculation that taks almost 1 minute"
>   printk("end of worker thread"); 
> 
> 
> ______________________________________________________________________
> Novo Servico IOL Dicionarios. 13 Linguas diferentes!
> Saiba mais - http://www.iol.pt/correio/rodape.php?dst=0501251
> 


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel 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