FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [October 2013 Threads] vTaskSuspendAll, xTaskResumeAll and configUSE_PREEMPTION = 0Posted 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 = 0Posted 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 = 0Posted 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 = 0Posted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|