# Memory ordering with FreeRTOS' CRITICAL\_SECTION

**URL:** <https://forums.freertos.org/t/memory-ordering-with-freertos-critical-section/23241>\
**Category:** ARM\
**Created:** [June 9, 2025, 3:41pm UTC](https://forums.freertos.org/t/memory-ordering-with-freertos-critical-section/23241 "2025-06-09T15:41:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan.misik.tescan](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@stefan.misik.tescan](https://forums.freertos.org/u/stefan.misik.tescan)\
**Post date:** [June 9, 2025, 3:41pm UTC](https://forums.freertos.org/t/memory-ordering-with-freertos-critical-section/23241/1 "2025-06-09T15:41:12Z")

</div>

Hello,

Does following code ensure memory access ordering:

```auto
int value;

void test() {
        taskENTER_CRITICAL();
        value += 1;
        taskEXIT_CRITICAL();
}

```

since `taskEXIT_CRITICAL()` (`vPortSetBASEPRI()`) does not include any of the `DMB`, `DSB` instructions. (Let’s assume global `value` is then usded/modified within interrupt handler that would be disabled by `portDISABLE_INTERRUPTS()`. Also I am specifically considering ARM\_CM4F port variant.)

Am I supposed to use my own/3rd party code (like C++’ `std::atomic<T>` ) to ensure so? If so, is that mentioned somewhere in FreeRTOS’ documentation?

Thank you.

Best Regards,  
Stefan Misik

---

<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 9, 2025, 4:46pm UTC](https://forums.freertos.org/t/memory-ordering-with-freertos-critical-section/23241/2 "2025-06-09T16:46:46Z")

</div>

The barrier instructions are not needed between tasks and/ISRs on the same core (and presumably you are talking a single core processor), but to make sure that a “memory” operation, that would typically be to a memory-mapped I/O device, has taken place before you continue.

Within a single core, the processor will handle any ordering requirements to make instructions do what they are supposed to. You need the critical section as increasing value by 1 may take more that one instruction (you are going to read value, increment that value, and then put it back) and you don’t want another changing operation to happen in the middle of that.
