What kind of procedure is used to calculate the thread

47 views Asked by At

there is a thread in the following task. How can I see whether Round Robin, FIFO or Preemptive Scheduling was used there?

void High_Thread(void const *argument)  

{  
   while(1)  
   {     
     GPIOE->DOUT_BYTE1=0xFF;  
   }  
}  

void Low_Thread(void const *argument)  
{  
   while(1)  
   {  
   GPIOE->DOUT_BYTE1=0x00;  
   }  
} 
osThreadDef(High_Thread, osPriorityNormal,1,0);  
osThreadDef(Low_Thread, osPriorityNormal,1,0); 
ThreadId_High=osThreadCreate(osThread(High_Thread), NULL);  
ThreadId_Low=osThreadCreate(osThread(Low_Thread), NULL); 

In this case, is that not a Round Robin procedure because the priorities are the same?

1

There are 1 answers

0
Brendan On

How can I see whether Round Robin, FIFO or Preemptive Scheduling was used there?

First; "preemptive" is not a scheduling algorithm, it's a property of a scheduling algorithm. For example, you can say "Round robin, variable time slice length, variable frequency and earliest deadline first are all scheduling algorithms that are preemptive".

Now; if you monitor the value last set by any GPIOE->DOUT_BYTE1=... (I'd assume using external hardware - e.g. an oscilloscope connected to a general purpose output's signal) then there's 3 possible results:

a) The output alternates in a regular pattern - e.g. like maybe 0xFF for 10 milliseconds, then 0x00 for 10 milliseconds, then 0xFF for 10 milliseconds, and so on (repeating forever). In this case the scheduling algorithm could be round robin or any of about 100 other scheduling algorithms (but not FIFO).

b) The output never changes - e.g. like maybe 0xFF forever. In this case the scheduling algorithm might be FIFO (because High_Thread was started first it will be the "first started task" until it terminates or blocks, but it never terminates or blocks so the other task will never get any CPU time); but it could also be any of about 20 other scheduling algorithms (but not round robin).

c) The output doesn't match either of the previous cases; so you know it's definitely not round robin or FIFO.

If you know that the scheduling algorithm must be either round robin or FIFO (and can never be any of about 120 other scheduling algorithms); then you can determine if it is round robin or FIFO.

However; it's a little rare to have special external monitoring like that. If you use a third thread (constantly reading/polling the value in GPIOE->DOUT_BYTE1) then that will ruin everything (e.g. with round robin the monitoring thread might only ever see the value 0xFF because it only gets CPU time after High_Thread was given CPU time).

Further; all of this is assuming that there's only one CPU. If there are multiple CPUs then both High_Thread and Low_Thread can be running on different CPUs at the same time (regardless of what the scheduling algorithm is) so you'd expect meaningless chaos.