I’m writing a multithreaded application, and I’m looking for advice about how to arbitrate access from multiple tasks to a resource. For simplicity, let’s assume that we have 3 tasks, A, B and C. I have a resource that can be accessed simultaneously by tasks B and C, but task A requires exclusive access to it (task A has to wait until both B and C release the resource and if Task A has the resource, task B and C have to wait until A releases it), but I want (for performance reasons) to allow tasks B and C to access at the same time. While my use case is different, you can think of this as task A writing to a memory area, and B and C reading from it.
How would I go about coordinating these tasks? Should I use two Mutexes? Like one between task A and B and another one between task A and C?
In my real case, there will be more than 2 tasks (possibly up to 20) that can access the resource at the same time, and one that requires exclusive access. Should I use 20 Mutexes? Or is there a more elegant solution?