from Hacker News

Keyway: A simple lock library

by adefa on 1/3/15, 4:26 PM with 3 comments

  • by zokier on 1/3/15, 11:58 PM

    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?