# vTaskSuspendAll() is causing assert in queue.c

**URL:** <https://forums.freertos.org/t/vtasksuspendall-is-causing-assert-in-queue-c/2770>\
**Category:** Kernel\
**Created:** [April 7, 2015, 7:01pm UTC](https://forums.freertos.org/t/vtasksuspendall-is-causing-assert-in-queue-c/2770 "2015-04-07T19:01:46Z")\
**Posts on this page:** 3\
**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:** [April 7, 2015, 7:01pm UTC](https://forums.freertos.org/t/vtasksuspendall-is-causing-assert-in-queue-c/2770/1 "2015-04-07T19:01:46Z")

</div>

**[lantczak](https://sourceforge.net/u/lantczak/)** wrote on [Tuesday, April 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/78e52fdf/#6449):

Hi,

I found following problem.

The vTaskSuspendAll() suspends scheduler. It is called in many places in internal  
freeRtos files (e.g. queue.c, task.c, heap\_4.c)

The problem is that if scheduler is suspended and the IRQ occur and inside this IRQ I call  
some API from freertos (e.g. xSemaphoreGiveFromISR or xQueueSendFromISR) then this call is  
triggering following assert:

```
            #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 )

```

)

```
            {

                            configASSERT( !( ( xTaskGetSchedulerState() ==

```

taskSCHEDULER\_SUSPENDED ) && ( xTicksToWait != 0 ) ) );

```
            }

```

File queue.c function xQueueGenericSend.

Simple test:

```
xSemaphoreHandle transmissionEnd;

transmissionEnd = xSemaphoreCreateBinary ();

UTILS_ASSERT (NULL != transmissionEnd);

vTaskSuspendAll();

xSemaphoreGiveFromISR (transmissionEnd, NULL); => this will trigger assert

```

I’m using v8.0.0 but I suspect that it is also in the newest version

Any ideas ?

* * *

Best regards

Łukasz Antczak

---

<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:** [April 7, 2015, 7:54pm UTC](https://forums.freertos.org/t/vtasksuspendall-is-causing-assert-in-queue-c/2770/2 "2015-04-07T19:54:02Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Tuesday, April 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/78e52fdf/#6164):

I just searched the source files (V8.2.1, not V8.0.0 admittedly) and can find four occurrences of:

```
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
```

Two are in event\_groups.c, so I have not looked at those. Two are in queue.c.

One of the two in queue.c is in xQueueGenericReceive(), and the other is in xQueueGenericSend() - but neither of those functions should get called in an ISR. xSemaphoreGiveFromISR() calls xQueueGiveFromISR() (or probably xQueueSendFromISR() in your version).

So I don’t know why you would hit those asserts - other than to say it looks like a non-ISR safe function is being called from an ISR.

I would recommend stopping on the debugger when the assert has been hit and looking at the call stack to see the sequence of function calls that took you to the assert.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 7, 2015, 8:44pm UTC](https://forums.freertos.org/t/vtasksuspendall-is-causing-assert-in-queue-c/2770/3 "2015-04-07T20:44:29Z")

</div>

**[lantczak](https://sourceforge.net/u/lantczak/)** wrote on [Tuesday, April 07, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/78e52fdf/#6164/6387):

Yes you are right. Thank you

From: Real Time Engineers ltd. [[mailto:rtel@users.sf.net](mailto:rtel@users.sf.net)]  
Sent: Tuesday, April 7, 2015 9:54 PM  
To: [freertos:discussion]  
Subject: [freertos:discussion] vTaskSuspendAll() is causing assert in queue.c

I just searched the source files (V8.2.1, not V8.0.0 admittedly) and can find four  
occurrences of:

configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER\_SUSPENDED ) && ( xTicksToWait  
!= 0 ) ) );

Two are in event\_groups.c, so I have not looked at those. Two are in queue.c.

One of the two in queue.c is in xQueueGenericReceive(), and the other is in  
xQueueGenericSend() - but neither of those functions should get called in an ISR.  
xSemaphoreGiveFromISR() calls xQueueGiveFromISR() (or probably xQueueSendFromISR() in your  
version).

So I don’t know why you would hit those asserts - other than to say it looks like a  
non-ISR safe function is being called from an ISR.

I would recommend stopping on the debugger when the assert has been hit and looking at the  
call stack to see the sequence of function calls that took you to the assert.

Regards.

* * *

vTaskSuspendAll() is causing assert in queue.c  
[https://sourceforge.net/p/freertos/discussion/382005/thread/78e52fdf/?limit=25#6164](https://sourceforge.net/p/freertos/discussion/382005/thread/78e52fdf/?limit=25#6164)

* * *

Sent from [sourceforge.net](http://sourceforge.net) because you indicated interest in  
[https://sourceforge.net/p/freertos/discussion/382005/](https://sourceforge.net/p/freertos/discussion/382005/)  
[https://sourceforge.net/p/freertos/discussion/382005](https://sourceforge.net/p/freertos/discussion/382005)

To unsubscribe from further messages, please visit  
[https://sourceforge.net/auth/subscriptions/](https://sourceforge.net/auth/subscriptions/) [https://sourceforge.net/auth/subscriptions](https://sourceforge.net/auth/subscriptions)
