Why second thread doesn't preempt the first one?

Alex kbyte at iol.pt
Mon May 9 15:21:42 UTC 2005


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?

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




More information about the users mailing list