# Put mutex in shared memory (FreeRTOS on two processors)

**URL:** <https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196>\
**Category:** Kernel\
**Created:** [May 31, 2022, 1:29pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196 "2022-05-31T13:29:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ckim](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@ckim](https://forums.freertos.org/u/ckim)\
**Post date:** [May 31, 2022, 1:29pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/1 "2022-05-31T13:29:46Z")

</div>

hi,

i am working on an arm cortex a9 dual core processor. on each core runs a FreeRTOS instance (they dont know anything about each other). The cores have on-chip-memory that they share. is it possible to place a mutex in this shared memory and let FreeRTOS on core 1 and FreeRTOS on core 2 access it to synchronize threads across cores?

many thanks in advance

---

<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:** [May 31, 2022, 2:10pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/2 "2022-05-31T14:10:28Z")

</div>

No, unfortunately that is not possible. Steam and message buffers are the only primitive designed for core to core communication.

---

<div class="post-metadata">

**Author:** ![ckim](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@ckim](https://forums.freertos.org/u/ckim)\
**Post date:** [May 31, 2022, 2:40pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/3 "2022-05-31T14:40:07Z")

</div>

can you also say why its not working. what would go wrong?

and how are those Steam and message buffers protected against simultaneous accesses? can a thread wait until something appears in the message buffer?

thanks for your reply

---

<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:** [May 31, 2022, 2:47pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/4 "2022-05-31T14:47:36Z")

</div>

See this approach [Simple Multicore Core to Core Communication Using FreeRTOS Message Buffers - FreeRTOS](https://www.freertos.org/2020/02/simple-multicore-core-to-core-communication-using-freertos-message-buffers.html)  
to get inspired 🙂

---

<div class="post-metadata">

**Author:** ![ckim](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@ckim](https://forums.freertos.org/u/ckim)\
**Post date:** [May 31, 2022, 2:52pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/5 "2022-05-31T14:52:36Z")

</div>

already read this article thanks… was more interested why one cannot use the mutexes for core to core communication.

do you know anything more? can you answer the questions above?

---

<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:** [May 31, 2022, 3:05pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/6 "2022-05-31T15:05:37Z")

</div>

The key difference between a StreamBuffer and a Queue/Semaphore/Mutex is that the StreamBuffer is only allowed to have a SINGLE write and a SINGLE reader (at a given time), so only one task can be blocked on it. This simplifies the logic such that it was possible to add a hook to allow cross-core/cross-kernel (AMP) notifications to StreamBuffers which would be very hard to add to Queues, since it would need to deal with having to figure out which kernel a give task on the waiting list belongs to.

---

<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:** [May 31, 2022, 3:05pm UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/7 "2022-05-31T15:05:38Z")

</div>

Since there is no underlying OS/kernel as on Linux managing a globally shared mutex data structure (in fact it’s 1 kernel hosted sync object ) there is just no way to do so with 2 completely separated/independent FreeRTOS executables.  
You’ve to use an interrupt based / message passing approach with this scenario.

---

<div class="post-metadata">

**Author:** ![ckim](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@ckim](https://forums.freertos.org/u/ckim)\
**Post date:** [June 1, 2022, 7:26am UTC](https://forums.freertos.org/t/put-mutex-in-shared-memory-freertos-on-two-processors/15196/8 "2022-06-01T07:26:55Z")

</div>

thank you so much all
