# Resuming after vTaskSuspend(NULL);

**URL:** <https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201>\
**Category:** Kernel\
**Created:** [January 5, 2016, 4:29pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201 "2016-01-05T16:29:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 5, 2016, 4:29pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/1 "2016-01-05T16:29:13Z")

</div>

**[andy-pevy](https://sourceforge.net/u/andy-pevy/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#c6a2):

Hi,

```
  I have a number of tasks and I am trying to synchronise one of them with another.

```

I am using the ST Cube tool to create the base code, and it starts all the tasks at boot time.

I therefore, within the first task issue a vTaskSuspend(TIMER\_TaskHandle); call. I was hoping that this would allow the second task to complete initializing some hardware (that takes a variable amount of time).

I then, from the second task issue a vTaskResume(TIMER\_TaskHandle);

But, the first task does not continue after the suspend line.

Code fragment :-

Timer task:

```
TIMER_Task_Suspended = TRUE;
vTaskSuspend(TIMER_TaskHandle); // Stop here until allowed to resume...
TIMER_Task_Suspended = FALSE; <- Never reached :(.....

```

Supervisor task :

```
if(MODE_DC == my_mode) <- This is true...
{
	vTaskResume(TIMER_TaskHandle);	// Re start the timer task.
}

```

So, Firstly, is what I am doing correct and allowed, and secondly, if it is, why does it not appar to work ?.

Thanks,  
Andy Pevy

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 5, 2016, 4:38pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/2 "2016-01-05T16:38:51Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#15ed):

Are you sure the value in TIMER\_TaskHandle is correct?

If so, then is the second task (the one that is calling vTaskResume()) higher, lower or equal priority to the first task? If it is higher priority then the first task will only execute when the higher priority task enters the Blocked state. It will enter the Blocked state if it makes a blocking FreeRTOS API call, such as vTaskDelay(), or xQueueReceive() on an empty queue with a block time specified.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 5, 2016, 5:01pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/3 "2016-01-05T17:01:08Z")

</div>

**[andy-pevy](https://sourceforge.net/u/andy-pevy/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#15ed/fde2):

Hi, The value in Timer\_TaskHandle is correct, and both tasks are running at the same priority.

The unblocking task enters “retval = xQueueReceive(Supervisor\_task\_queueHandle, (Transfer\_Type \*) &supervisor\_inds, slot\_time.sleep\_time);” a few lines later so it should allow the timer task to run.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 5, 2016, 5:08pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/4 "2016-01-05T17:08:46Z")

</div>

**[andy-pevy](https://sourceforge.net/u/andy-pevy/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#1010):

Would adding a vTaskDelay or taskYIELD be a way of releasingf the timer task ?.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 5, 2016, 5:20pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/5 "2016-01-05T17:20:14Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#91a2):

That shouldn’t be necessary.

Another thought - if the tasks are the same priority - are you 100% sure the task is suspended before you try un-suspending it?

For example, if:

1. the first task set TIMER\_Task\_Suspended to true, then got swapped out before it called vTaskSuspend(),
2. Then the second task executed, did its thing, and called vTaskResume(),
3. Then the first task executed again and called vTaskSuspend()

you would end up with the behaviour your have observed.

Try creating the first task with a priority above that of the second task, so you know there is no chance of the second task executing until the first task has actually entered the Suspended state. Then when the first task leaves the Suspended state it can call vTaskPrioritySet( NULL, [whatever] ); to set its priority back down to the one you really want it to run at.

Alternatively, if the task is created before the scheduler has started, you can also suspend it before the scheduler starts, that way it will already be in the suspended state before any tasks run. vTaskSuspend() is one of the functions that it is ok to call before starting the scheduler.

Regards.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [January 5, 2016, 5:21pm UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/6 "2016-01-05T17:21:59Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, January 05, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#dd8f):

By the way, you can use [eTaskGetState()](http://www.freertos.org/a00021.html#eTaskGetState) to determine the state of a task.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [January 6, 2016, 8:11am UTC](https://forums.freertos.org/t/resuming-after-vtasksuspend-null/4201/7 "2016-01-06T08:11:53Z")

</div>

**[andy-pevy](https://sourceforge.net/u/andy-pevy/)** wrote on [Wednesday, January 06, 2016](https://sourceforge.net/p/freertos/discussion/382005/thread/b9338598/#c7d8):

Bingo, looking at the relative timings, I think that this is a distinct possibility.

I will re-work the control logic to ensure that the timings are correct.

Thanks for your help.

Andy
