It's not a semaphore #1
Replies: 2 comments
-
First of all thank you for your opinion and your contribute @hellmutbrudny and let me also excuse me for my bad english. |
Beta Was this translation helpful? Give feedback.
-
Hi @IWILZ, No worries, for me too English is not the first language ;). Yes, I'm referring to the same definition of semaphore. What your implementation lacks is "mutual exclusion". It is mentioned on this wiki page you linked but quite scarcely. You can find it in following quote: So, as I mentioned before, your example works as there is no real competing for the resources as you have only one writer and one reader for each queue. In such a case you don't need to worry about that two cores will try to acquire semaphore for writing in the same time. In other scenarios that may not work. But synchronization of concurrent processes is quite a complicated subject in total. You can start reading more there: For my projects on Pico it's enough to use core library mutex. I guess it's enough for most of cases as we have only two cores/threads. I use my own wrapper class for that: And for the last: if your implementation works for you then it's ok. Just be aware that it's not enough for general purpose semaphore. And because of this: https://www.hackster.io/iwilz/picosem-a-raspberry-multi-tasking-under-arduino-framework-bc2d80 it may reach and mislead other users ;). |
Beta Was this translation helpful? Give feedback.
-
Hi @IWILZ,
sorry to say that but your library doesn't synchronize like one would expect from "real semaphores". This is just two simple flags wrapped in class. It may work in your example because you use two separate buffers for both cores but in case of a single resource race (ex. both cores want to write to the same place in memory) it will fail.
If it works for you then ok but maybe add a proper statement in readme? Because now it may mislead some other users.
If you would like me to explain it deeper then don't hesitate to contact me.
Beta Was this translation helpful? Give feedback.
All reactions