Semaphore may block

What do you mean by that? There are several implementations of reader/writer locks on FreeRTOS. I have presented one in my book, you can find the code here: Extra Materials Archive. click the “Extra materials file” and look in the code tree in chapter 6, there should be a file named rwlock.cpp. From all I can tell it works, but admittedly I have little feedback from my readers.

I won’t buy Your book, but it looks interesting. You seem to be the right person to talk with. Your read-lock is written in C++ and is still invisble to me. I’ve been asking Google and all i got was a semaphore in FreeRTOS. The FreeRTOS-community has both, a mutex and a semaphore for the same problem. High performance applications still crash on every platform, no fake news over satelite. Obviously the heap was the problem, forbidden in NASA.

How can Your read-lock work without two linked lists? I mean, i had a two-dimensional linked list and it didn’t work when locking two muteces at a time.

Invalid file on Android.

well, to me it seems as if your metaphor of a two dimensional list of waiting threads for the lock does not map well to a synchronization object because it can only select one thread when free, so at some point you must fold your two lists into one so that there is one deterministic entry to select on top of the list at any time. Trying to build a lock that internally uses two queues to select from to me does not look like a natural way for me to do that.

I still think that a modified r/w lock would be the most natural way to model what you mean you need to do, but as usual, there is more than one way to skin a cat. Best of luck with your endeavours!

1 Like

The point is, i can not append directly to the owner. My task may be the owner of multiple muteces. This way i get two lists, one list of owners and one with waiting tasks.

Thank You RAc, merry christmas.

One point is that FreeRTOS doesn’t keep a list of Mutexes that a task own, only the owner of each Mutex. For a Read-Write lock, this would need to be a list of Read Owners.

My point about “misusing” terminology, is that from what you seem to be describing, you don’t have a “mutex” that various tasks take, do there work, and then release, but some sort of “scheduler” that maybe is doing some of the work itself. You also seem to have defined way the ability to use task priority for scheduling control, as you define very limited levels based on the type of task.

1 Like

I understand now, You got me.

Thank You very much for making this possible and correcting me.

Merry christmas.