I have scenario where I have a shared resource and there are multiple consumers (Threads) of that resource (let say RES) . Those consumers simply consume that resource in read only manner. Similarly there is a modifier (Another Thread) which runs occasionally and update the resource RES.
I don't want my consumer threads to use resource RES if modification is in progress. To achieve this scenario I have created a monitor object which consumer has to acquire to proceed with using RES and Same is the case of modifier.
As the code is working fine but there is a possibility of optimisation, which actually is that I should not synchronize the consumer threads with each other as they are not doing any modification in the resource. What i am trying to achieve is that synchronisation between two set of threads. What I mean -
- list TL1 which has consumer threads
- list TL2 which has modifier threads
TL1 and TL2 should be mutually exclusive as whole but NOT the threads within TL1 and TL2.
As I could not come up with any such solution what I am trying as another option is to create let say 10 monitor objects and if consumer acquire any of the monitor object it is good to go, But modifier would have to acquire all the monitor objects before proceeding for modification. As modification is far low frequent scenario in my use case it would result in better throughput from consumer perspective.
Need suggestion on this.