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

vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by pronkin on October 24, 2013

Hi everybody, for one of my project I use Cooperative Multi-threading (configUSE_PREEMPTION = 0)

And think that vTaskSuspendAll and xTaskResumeAll are useless in this case Since xTaskResumeAll may cause YIELD and I use heap_3 Malloc scheme

vTaskSuspendAll();
{
pvReturn = malloc( xWantedSize );
traceMALLOC( pvReturn, xWantedSize );
}
xTaskResumeAll(); //It can YIELD here

It means pvPortMalloc can cause a context switch (little confusing)

Here is some bad scenario: 1) Some work with critical data structures 2) Decide to malloc some memory, while data structures not correct 3) After pvPortMalloc other task can get access to wrong data 4) End work with critical data structures and free memory

Maybe in case of configUSE_PREEMPTION = 0 vTaskSuspendAll and xTaskResumeAll should be empty?


vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by edwards3 on October 24, 2013

Initial thought is to keep them, but to just not yield if configUSE_PREEMPTION is 0, but second thought is you might be right to just compile them out all together.

When the RTOS is suspended interrupts can happen but context switches cant, but if you are using cooperative scheduling then context switches are not going to happen anyway.

But even when configUSE_PREEMPTION is 0 a context switch can happen if you for example send to a queue and there is a task blocked on the queue - but that is more expected behavior whereas calling resumeAll and getting a context switch isnt.


vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by pronkin on October 24, 2013

hm, yes vTaskSuspendAll can be used in cooperative sheduller to avoid context switch in QueueSend or SemaphoreGive, so vTaskSuspendAll can't be empty. But context switch in pvPortMalloc not expected (for me)


vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0

Posted by richardbarry on November 7, 2013

Take a look at the head revision in SVN - the co-operative behaviour has been changed, and as such it will probably be released as V7.6.0.

Now a context switch is only performed if the calling task is blocked. For example, if you attempt to write to a queue with a block time specified and the queue is full then the task will block and another task will start running. However, if you successfully write to the queue, and writing to the queue causes a task of higher priority to unblock, then a context switch will not occur - the original task will continue executing until it either blocks or calls taskYIELD().

Likewise when changing the priority of another task, or unsuspending another task, etc. A context switch will not occur even if the API call makes a higher priority task ready to run.

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