Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


cooperative vs preemptive

Posted by Nobody/Anonymous on January 15, 2005
Hi, is ther a configuration maro for cooperative/ preemptive compilation? If I need only coperative OS, will it take less ram and rom?

RE: cooperative vs preemptive

Posted by Richard on January 15, 2005
See the page:


Also, most ports have a macro portUSE_PREEMPTION. This can be found near the top of the portmacro.h file for the port you are using (described on the port documentation page). It is best to set portUSE_PREEMPTION to either 1 or 0 (to use preemptive or cooperative respectively), and then pass this macro to vTaskStartScheduler(). For example:

[in portmacro.h]
#define portUSE_PREEMPTION 1

[in your application source code]
vTaskStartScheduler( portUSE_PREEMPTION );

The amount of RAM and ROM used depends on how many tasks you create, not which scheduler is used. However, the scheduler processing overhead is less with the cooperative scheduler.

If RAM usage is important then consider how you create tasks. Each task requires its own stack so the fewer tasks the less RAM is required.

For example, if your application has one periodic function that must run with very regular frequency, and a few other functions that can be considered 'background' then:

Option 1:
You can create one task for each function and use preemptive scheduling. The periodic task has the highest priority to ensure it meets its timing requirements. This gives the simplest design but uses the most RAM.

Option 2:
You can create a high priority task for the periodic function, and a single low priority task for the other functions and use the preemptive scheduler. The low priority task would contain some kind of loop that loops through all the background functions. Whenever the periodic function needed to execute the background function task would be preempted. This option uses less RAM as there are less tasks, but still maintains the timing requirements of the periodic task. Provided your background functions never block you could even add them to the Idle task - saving even more RAM.

Option 3:
This is a hybrid option. It is the same as option 2, but using the cooperative scheduler. If the periodic task can be signalled by an interrupt then you can perform a context switch to the periodic task from the interrupt handler even though the cooperative scheduler is being used.

There will be some more WEB documentation on this very subject appearing in the next week or so.


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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner