I’m trying to implement a Readers–writer lock using using two mutexes and an integer counter as described in:
Concurrent control with “readers” and “writers”
October 1971 Communications of the ACM 14(10):667-668
Pierre-Jacques Courtois
F. Heymans
David Parnas
(See also: https://en.m.wikipedia.org/wiki/Readers–writer_lock .)
The goal is to protect a buffer so that a writer has an exclusive lock, but multiple readers can share a read lock. In this scheme, the “exclusive” (or “global”) lock is acquired by the first reader to enter the critical section and the last reader to leave it. Those can be different tasks. When this happens, I am getting this assert:
assertion "pxTCB == pxCurrentTCB" failed: file "Generated_Source\PSoC6\pdl\rtos\FreeRTOS\10.0.1\Source\tasks.c", line 3910, function: xTaskPriorityDisinherit
The comment before that line says:
/* A task can only have an inherited priority if it holds the mutex.
If the mutex is held by a task then it cannot be given from an
interrupt, and if a mutex is given by the holding task then it must
be the running state task. */
Is this a limitation of FreeRTOS Semaphores, or do I have a bug somewhere? Is there a better way to implement a Readers–writer lock in FreeRTOS?