# implementation of vTaskSuspendAll() in 5.20, 

**URL:** <https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616>\
**Category:** Kernel\
**Created:** [June 11, 2009, 3:38pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616 "2009-06-11T15:38:53Z")\
**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:** [June 11, 2009, 3:38pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/1 "2009-06-11T15:38:53Z")

</div>

**[kolodko1](https://sourceforge.net/u/kolodko1/)** wrote on [Thursday, June 11, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456):

Hi

Port PIC24, ver, 5.20  
Compilator:&nbsp; pic30-gcc v3.12 from microchip, opt. flag O2 + some minors flags

Disassembly listing for vTaskSuspendAll()  
--------------------------------------------------------------------------------------------------------  
1015:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
1016:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void vTaskSuspendAll( void )  
1017:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {  
1018:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /\* A critical section is not required as the variable is of type  
1019:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; portBASE\_TYPE. \*/  
1020:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++uxSchedulerSuspended;  
1399A&nbsp; 81D890&nbsp;&nbsp;&nbsp;&nbsp; mov.w 0x3b12,0x0000  
1399C&nbsp; E80000&nbsp;&nbsp;&nbsp;&nbsp; inc.w 0x0000,0x0000  
1399E&nbsp; 89D890&nbsp;&nbsp;&nbsp;&nbsp; mov.w 0x0000,0x3b12  
1021:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }  
139A0&nbsp; 060000&nbsp;&nbsp;&nbsp;&nbsp; return  
--------------------------------------------------------------------------------------------------------

So it takes 3 instruction: load uxSchedulerSuspended to WREG0, increment WREG0 and store results.  
So I do not see reason for comment:  
&nbsp;&nbsp;&nbsp; /\* A critical section is not required as the variable is of type  
&nbsp;&nbsp;&nbsp; portBASE\_TYPE. \*/

Please comment.  
Best Regards  
/Greg

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 11, 2009, 6:14pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/2 "2009-06-11T18:14:30Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Thursday, June 11, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/3001):

That does not look right!

---

<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:** [June 11, 2009, 6:28pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/3 "2009-06-11T18:28:19Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, June 11, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/3001/bde0):

That is a very recent change, and I agree it looks wrong.&nbsp; I will investigate.&nbsp; There will be a new release on the 22nd so it can get fixed quickly.

Thanks for pointing this out.

Regards.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 11, 2009, 7:36pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/4 "2009-06-11T19:36:21Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Thursday, June 11, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/59c3):

Actually, I think it is ok, let me explain.

If uxSchedulerSuspended starts off non-zero, then we don’t need a critical section, as an interrupt during the execution of the code will not change the thread of execution, so the non-atomic sequence will execute ok (a key fact is that no interrupt will change the value of this variable and not set it back to what it started as).

If uxSchedulerSuspended starts of zero, then it is possible for the thread of execution to be interrupted, but if we do execute a task switch, then when we get switched back, by definition the variable is zero again (if not, we couldn’t have been been switched back to).

The key fact is that due to the nature of this variable, a task can not see it changed by another task, it will always be zero if something else can run (that task can change it, but must restore it before you get control back).

In fact I think it will work even if the read and writes to uxSchedulerSuspended aren’t atomic in most practical situations (the most likely would be hitting a nesting depth suspensions of 256 on a machine that writes 1 byte at a time, then the counting from 255 to 256 might go 255-\>0(write low byte) -\> 256 (write high byte) and if you get in interrupt for the moment when it is 0 you will have a problem.

---

<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:** [June 11, 2009, 8:15pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/5 "2009-06-11T20:15:26Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, June 11, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/59c3/6a1c):

Excellent.&nbsp; Thanks for the clarity.

I would like to say "that was exactly what I was thinking", but um…well its getting late.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [June 12, 2009, 11:17am UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/6 "2009-06-12T11:17:54Z")

</div>

**[kolodko1](https://sourceforge.net/u/kolodko1/)** wrote on [Friday, June 12, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/3493):

Hi

Hmmm…, yes, that’s reasonable explanation. Of course based on assumption that read and write is atomic.

Regards  
/Greg

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 12, 2009, 3:54pm UTC](https://forums.freertos.org/t/implementation-of-vtasksuspendall-in-5-20/2616/7 "2009-06-12T15:54:34Z")

</div>

**[richard\_damon](https://sourceforge.net/u/richard_damon/)** wrote on [Friday, June 12, 2009](https://sourceforge.net/p/freertos/discussion/382005/thread/7580a7dd/#8456/3493/af55):

Yes, the access to the count needs to be atomic (or at least atomic "enough", the bits that might be non-zero need to be accessed atomically, depending on how many layerd of vTaskSuspendAll() might be nested, that may just be the bottom couple of bits.
