# Resources sharing

**URL:** <https://forums.freertos.org/t/resources-sharing/16600>\
**Category:** Kernel\
**Created:** [January 20, 2023, 5:59pm UTC](https://forums.freertos.org/t/resources-sharing/16600 "2023-01-20T17:59:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kittu20](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kittu20](https://forums.freertos.org/u/Kittu20)\
**Post date:** [January 20, 2023, 5:59pm UTC](https://forums.freertos.org/t/resources-sharing/16600/1 "2023-01-20T17:59:47Z")

</div>

As i understand Two tasks can share the same resources but not at same time.

What are examples of resources sharing other than CPU time and memory in an RTOS application?

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [January 20, 2023, 6:08pm UTC](https://forums.freertos.org/t/resources-sharing/16600/2 "2023-01-20T18:08:20Z")

</div>

For instance 2 or more tasks access the same piece of hardware like a (the same) UART controller.  
Then the access of each task must be protected against getting preempted by the other task e.g. using a mutex in an appropriate way.

---

<div class="post-metadata">

**Author:** ![Kittu20](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kittu20](https://forums.freertos.org/u/Kittu20)\
**Post date:** [January 31, 2023, 9:50pm UTC](https://forums.freertos.org/t/resources-sharing/16600/3 "2023-01-31T21:50:58Z")

</div>

Do you use mutex when your two task share the CPU?

---

<div class="post-metadata">

**Author:** ![kstribrn](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/kstribrn/32/6511_2.png) [@kstribrn](https://forums.freertos.org/u/kstribrn)\
**Post date:** [January 31, 2023, 10:56pm UTC](https://forums.freertos.org/t/resources-sharing/16600/4 "2023-01-31T22:56:41Z")

</div>

Generally no - that’s the purpose of FreeRTOS. FreeRTOS tasks are swapped in an out (or scheduled and unscheduled) according to their priority and their ability to run. For more, I’d reference [this page on scheduling](https://www.freertos.org/implementation/a00008.html)

If you want true parallelism, you’ll need to have the two tasks running in different cores (see [FreeRTOS AMP or SMP](https://www.freertos.org/single-core-amp-smp-rtos-scheduling.html0) however this can bring up the problem of shared memory which would require a mutex.

---

<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:** [February 1, 2023, 12:28pm UTC](https://forums.freertos.org/t/resources-sharing/16600/5 "2023-02-01T12:28:56Z")

</div>

The one case to use a mutex for sharing a “CPU” is if using some special feature of the CPU that isn’t saved as part of a context switch. This is a very unusual situation.

---

<div class="post-metadata">

**Author:** ![Kittu20](https://avatars.discourse-cdn.com/v4/letter/k/b3f665/32.png) [@Kittu20](https://forums.freertos.org/u/Kittu20)\
**Post date:** [February 1, 2023, 4:02pm UTC](https://forums.freertos.org/t/resources-sharing/16600/6 "2023-02-01T16:02:57Z")

</div>

> [@hs2](#):
>
> For instance 2 or more tasks access the same piece of hardware like a (the same) UART controller.  
> Then the access of each task must be protected against getting preempted by the other task e.g. using a mutex in an appropriate way.

Have you solved a problem in which resources was time critical?

can you explain this problem a bit, it will give me a real idea

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [February 1, 2023, 4:25pm UTC](https://forums.freertos.org/t/resources-sharing/16600/7 "2023-02-01T16:25:08Z")

</div>

Using a mutex to protect shared resources or data is a common multi-tasking programming idiom. You’ll find lots of explanations and use cases in the web.
