# FreeRTOS+FAT thread safety

**URL:** <https://forums.freertos.org/t/freertos-fat-thread-safety/20689>\
**Category:** Libraries\
**Created:** [June 12, 2024, 10:09am UTC](https://forums.freertos.org/t/freertos-fat-thread-safety/20689 "2024-06-12T10:09:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TanD](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@TanD](https://forums.freertos.org/u/TanD)\
**Post date:** [June 12, 2024, 10:09am UTC](https://forums.freertos.org/t/freertos-fat-thread-safety/20689/1 "2024-06-12T10:09:13Z")

</div>

FreeRTOS+FAT mentions that it is **Fully thread aware**. I have some doubts regarding this.

- What does Fully thread aware exactly mean?
- How does it differ from thread safe?
- Is it safe to use in multi threaded environment?

Tried looking around on web but could not find a clear difference.  
Thanks

---

<div class="post-metadata">

**Author:** ![carlk3](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/carlk3/32/266_2.png) [@carlk3](https://forums.freertos.org/u/carlk3)\
**Post date:** [June 12, 2024, 6:21pm UTC](https://forums.freertos.org/t/freertos-fat-thread-safety/20689/2 "2024-06-12T18:21:27Z")

</div>

I can’t help you with your first two questions, but I’ve been using it in heavily multi-threaded applications for a long time. If you compare it to [FatFs](http://elm-chan.org/fsw/ff/00index_e.html), for example, FatFs has some support for “re-entrancy” or thread safety, but it does not appear to have sufficient FAT and directory locking in FatFs to make operations like `f_mkdir`, `f_chdir` and `f_getcwd` thread safe, whereas FreeRTOS+FAT does.

Take a look at [ff\_locking.c](https://github.com/FreeRTOS/Lab-Project-FreeRTOS-FAT/blob/main/ff_locking.c) and [vMultiTaskStdioWithCWDTest](https://github.com/carlk3/FreeRTOS-FAT-CLI-for-RPi-Pico/blob/a363bb3f87abff77642a160602f748c3582bae49/examples/command_line/tests/ff_stdio_tests_with_cwd.c#L1163C6-L1163C32) in [ff\_stdio\_tests\_with\_cwd.c](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/basic_stdio_API_tests.html).

Also, see [Announcement: FreeRTOS Symmetric Multiprocessing (SMP) +FAT running on Raspberry Pi Pico](https://forums.freertos.org/t/announcement-freertos-symmetric-multiprocessing-smp-fat-running-on-raspberry-pi-pico/13440) for an example.

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [June 13, 2024, 5:32am UTC](https://forums.freertos.org/t/freertos-fat-thread-safety/20689/3 "2024-06-13T05:32:33Z")

</div>

> [@TanD](#):
>
> - What does Fully thread aware exactly mean?
> - How does it differ from thread safe?

I think thread aware and thread safety are used interchangeably i.e. you can use this library in multi-threaded environment.

---

<div class="post-metadata">

**Author:** ![carlk3](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/carlk3/32/266_2.png) [@carlk3](https://forums.freertos.org/u/carlk3)\
**Post date:** [June 13, 2024, 3:52pm UTC](https://forums.freertos.org/t/freertos-fat-thread-safety/20689/4 "2024-06-13T15:52:38Z")

</div>

One possible semantic difference might be regarding performance. I can imagine a “thread safe” implementation that just serializes all access to the file system with a single mutex. However, this would perform poorly in a multi-tasking, multi-processing, multi-“disk” environment; you’d really want finer-grained locking that maximizes concurrency.
