There are two groups of concurrent processes, readers and writers, sharing a file. When two or more reader processes access the shared data at the same time, no side effects will occur, but if a writer process and other processes (reading process or writing process) Access to shared data at the same time may cause data inconsistency errors.
Therefore
the requirements are:
- Allow multiple readers to read files at the same time;
- Only one writer is allowed to write information in the file;
- Any writer does not allow other readers or writers to work before completing the writing operation;
- Before the writer performs the writing operation, all existing readers and writers should be allowed to exit.
Code:
