Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] create file in file_lock ctor #175

Open
timblechmann opened this issue May 27, 2022 · 2 comments
Open

[feature request] create file in file_lock ctor #175

timblechmann opened this issue May 27, 2022 · 2 comments

Comments

@timblechmann
Copy link
Contributor

the file_lock ctor throws if the file does not exist. it would be nice to be able to have a signature that creates the file automatically if it doesn't exist. currently the ctor uses open_existing_file, maybe it could be extended by a boolean argument to use create_or_open_file if the users wants that semantics.

thoughts?

@igaztanaga
Copy link
Member

What is the advantage of doing that inside file_lock instead of doing it externally?

@timblechmann
Copy link
Contributor Author

  • only a single system call is required (open or create_file take care of the rest), so it should be slightly faster
  • it reduces the risk of race conditions when multiple processes may create the file or delete the file. open / create_file is be atomic on the filesystem level, but once people start using library wrappers like filesystem::exists(), creating a file with ofstream, change permissions etc a layman developer will easily run into unintended race conditions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants