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

Cooperative locking #11

Open
dimo414 opened this issue Dec 14, 2021 · 1 comment
Open

Cooperative locking #11

dimo414 opened this issue Dec 14, 2021 · 1 comment

Comments

@dimo414
Copy link
Owner

dimo414 commented Dec 14, 2021

bash-cache provides optional support for cooperative locking via bc::locking_cache, which ensures concurrent calls to the same function will not race. It would be nice to add something similar to bkt.

There's already a simple FileLock implementation, though it doesn't support waiting for the lock to release at present. notify looks useful, but a simple polling loop might be sufficient (and more lightweight) given that the process won't be doing anything else until the lock releases.

@zbentley
Copy link

flock(2) doesn't take a timeout, but otherwise may satisfy locking needs here. I'm unsure how portable it is to Windows, or if that's a priority.

Given bkt's nature, the lack of a timeout to flock is not a big deal; do a blocking flock in a thread and simply give up on the thread if a timer expires (or use alarm, but that's harder to get right).

I wouldn't recommend notify/any of the fsnotify/dnotify/inotify family. They tend to have complicated APIs and be unexpectedly lossy when it comes to buffer overflows.

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