Skip to content

Keyway: A simple lock library

blog.strieber.org
10 pointsadefa3 comments
On HN

Comments

Maybe I'm missing something, but shouldn't locks generally have some protections against race conditions? E.g. starting from line 15:

    acquire_lock_for() {
      if not_locked $1; then
        lock_log "Creating $1 lock."
        touch "$LOCK_DIR/$1".lock
        check_execution "acquire lock"
      fi
    }
what if another process creates lock file between the `if not_locked` and `touch` lines?

I've updated the library and blog if you'd like to take a look. Thanks for your feedback!

Great point. I'll update the library and my blog post with a fix for this. Thanks!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.