Open cppntn opened 4 years ago
For the benefit of searchability, this is also called a readers-writers-lock, or an RW-lock.
I would be interested in the same thing.
Implementation-wise, it would be possible to do this on top of the current classes: One could have a regular filelock around a shared file that contains the current number of readers / a writer flag. However, that would require three files, and some code would need to compose three corresponding filenames. Hence, if it was possible to have such a simple API as suggested above, that would be welcome!
Are there alternative terms to be considered? I like mode = "reader" / "writer", but could also imagine "shared" / "exclusive", for instance.
Hello, if you make a PR for this (with tests) we would be happy to review, thanks!
Is there a way to add an argument to the LockFile class, such as "writer" or "reader", in order to:
1) allow multiple readings between processes and threads (like
with LockFile("file.txt", mode="reader"):
) avoiding writing2) not allow readings while writing (like
with LockFile("file.txt", mode="writer"):
)Thanks
Edit: the operations are not referred to the file "file.txt", that file is just used as a locker.