vTaskSuspend and xTaskResumeAll

karsten_klein wrote on Friday, November 14, 2008:

I have a question concerning taskSuspend and resuming it.

There is one Task (TASK_A)  which will be suspended by using:
vTaskSuspend( NULL ).

The resume of TASK_A will be done in an ISR  after a DMA transfer_complete_interrupt by:


In an other Task (TASK_B)  it might happen in the meanwhile (where the TASK_A is suspended) , that a vTaskSuspendAll() and a xTaskResumeAll() is executed.

Does the xTaskResumeAll() from TASK_B automatically resume the TASK_A as well, or is there a difference between the both mechanisms.

Thank you very much in advance


rtel wrote on Friday, November 14, 2008:

A couple of points:

1) Be careful with the usage scenario of using xTaskResumeFromISR().  If you are wanting to wake a task when an event occurs it is normally more appropriate to use a semaphore, otherwise events can be missed.

2) xTaskResumeAll() does not effect tasks that are in the suspeneded state.  Probably not a good name for the function (in fact in SafeRTOS the name was changed to xTaskResumeScheduler()).  SuspendAll() suspends the scheduler so no reschedules occur.  ResumeAll() resumes the scheduler so priority based scheduling happens as per normal.  The state of individual tasks is not effected.


karsten_klein wrote on Friday, November 14, 2008:

Hi Richard,
thank you very much. Item 2 is understood.

But how can events be missed by using xTaskResumeFromISR() ?

The DMA-Transfer_Complete interrupt (by the way it´s an AVR32) occured and xTaskResumeFromISR(xHandleBusTask) is executed.
So the TASK_A should be resumed, and scheduled again, as soon as possible.

Or are there other items I didn´t concider ?

Best regards

rtel wrote on Friday, November 14, 2008:

Consider the case where a task is structured thus:

void vATask( void * pvParameters )
________/* Wait for an event. */
________vTaskSuspend( NULL );

________/* If the task is running now then the interrupt must have
________resumed it. */

________/* A */

________/* Process the event. */

________/* B */

so this is a simple task that executes each time it is resumed, processes an event that resumed it, then suspends itself again to wait for the next event.

The problem is, if the event occurs again anywhere between A and B it will have occurred before the task had suspended itself - the interrupt will try to resume the task but it was not actually suspended.  The task will then suspend itself when it goes back to the top of the loop, not knowing there is already data to process.

If you use a binary or counting semaphore this problem goes away.  Instead of suspending itself the task blocks on the semaphore.  In the ISR the code simply gives the semaphore to unblock the task.


karsten_klein wrote on Friday, November 14, 2008:

understood so far. This can happen. A semaphore is the better choise for that.

In my situation there is always a gap of at least 3ms between the TaskSuspend and the event (ISR)  which resumes the task. The event is allways a direct followup of the start of the DMA-transfer which happen straight before the taskSuspend.

Anyway I understand the point and will investigate in going with a semaphore. This seems to be more safety.

Thank you very much.

Best Regards