Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Coroutine Scheduling

Posted by dennis on January 26, 2007
Hi all,

I'm new to freeRTOS and coroutine.

I have a question about the function of coroutine scheduler in the documentation, which says:

"vCoRoutineSchedule() executes the highest priority co-routine that is able to run. The co-routine will execute until it either blocks, yields or is preempted by a task. Co-routines execute cooperatively so one co-routine cannot be preempted by another, but can be preempted by a task."

The above paragraph seems a little bit contradicting to me.

If the scheduler always schedules the highest priority co-routine first (presumably, at every system clock tick), then I would think that a higher priority coroutine can preempt a lower priority coroutine.

However, what it continues to say is that a coroutine will keep running until it blocks itself (by crDELAY, crQUEUE_SEND, or crQUEUE_RECEIVE). In that case, what is the use of priority for coroutine?

Also, assuming no tasks are running, when coroutine A (higher priority) blocks itself for t ms, and coroutine B (lower priority) starts running, will coroutine B stops and let A to run after t ms?

Thanks in advance!

Dennis

RE: Coroutine Scheduling

Posted by Richard on January 26, 2007
Co-routines will not preempt each other. Therefore when a co-routine is selected to run it will continue to be the selected co-routine until such a time that it blocks or calls yield. When a co-routine blocks the scheduler then re-evaluates which co-routine should be selected to run and will at that time choose the highest priority co-routine that is able to run (i.e. is not blocked).

Co-routines use a cooperative system, whereas tasks can be configured to be wither cooperative or preemptive. The priority is used to select the next co-routine to run at each decision point.

Regards.

RE: Coroutine Scheduling

Posted by Jeff Smith on January 27, 2007
Hi Dennis,

You've got to be sure what "preempt" means. richard already said it but maybe my simple explanation will help: Coroutines are only cooperative (in your example cr A blocks itself by crDELAY, etc. therefore cr B can run while A is blocked)

Of course priorities are important each time vCoRoutineSchedule() determines which task should run next.

RE: Coroutine Scheduling

Posted by dennis on January 29, 2007
Thank you Richard and Jeff!

From your description, can I say that when my coroutine executes
crDELAY( xHandle, xDelayTime );
there is no gurantee that the coroutine will run after xDelayTime (or even close to it) because some other coroutine might be running and not blocking itself?

Cheers.

Dennis

RE: Coroutine Scheduling

Posted by Richard on January 29, 2007
That is correct. It is the nature of cooperative scheduling. If you need preemption then tasks are the only choice. Using cooperative scheduling you have to ensure your low priority co-routines call yield often enough to ensure your high priority co-routines meet their real time deadlines.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists