bkt icon indicating copy to clipboard operation
bkt copied to clipboard

Cooperative locking

Open dimo414 opened this issue 4 years ago • 1 comments

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.

dimo414 avatar Dec 14 '21 21:12 dimo414

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.

zbentley avatar Feb 20 '22 06:02 zbentley