I would like to have the following scheme:
one mutex struct.
a writer can enter the critical section only if no other thread is there.
a reader can enter the critical section only if the other threads currently there are also readers.
I am not sure how to implement this with critical_sections (as I don’t want the readers to be mutually
exclusive)
Any ideas?
Thanks!
You may use semaphores.
writer is inside the critical
section.
You can check on most semaphore structures how much permits are available and when … the maximum amount of permits equals the available amount of permits you know that there is no reader inside the critical section.
Some pseudo code
Writer
Reader