hermarcel wrote on Wednesday, May 22, 2013:
Hello,
I am designing my first real FreeRTOS project and would like your opinion on the following.
I have a common datastructure that is frequently updated with new data from the outside world. Updates are done by a gatekeeper task. This is the only task that will be updating the structure.
Several tasks will need read-access to the data. These tasks should not have to wait for each other (they are only reading).
I would like to create a situation where the writer indicates it is about to update the struct and then blocks until all current readers are done with it. When the writer is updating the struct, the readers will wait (block) until the writer is done.
What would be a nice strategy to go with?
I could have the writer-task take a binary semaphore when it is about to update the structure. And give the semaphore when updating is finished. The reader-tasks should then have a means to check is the semaphore is taken or not.
After the writer has taken it’s semaphore it could block until a counting-semaphore reaches zero to indicate that no reader-tasks are using the structure.
Is this a viable approach? There seem to be no RTOS api-calls for checking if a binary-semaphore is taken. Nor can I find funtions that block until a counting semaphore reaches zero.
What approach would you take?
Thank you,
Marcel