Above is reader write problem solution where writer has preference over reader.
Suppose, initially 1000 readers start executing code to read data (suppose reading data code is huge and takes 1 sec for each thread) then 1 writer tries to write data. So the writer has to wait for 1000 readers to finish first (i.e., 1000 sec).
For example, in an application where 1 writer updates time and many readers read time, the writer has to wait for 1000 seconds, which is huge.
Is there any solution in which, when a writer tries to write, all readers will be preempted until the writer completes its task?