code: func flock(db *DB, mode os.FileMode, exclusive bool, timeout time.Duration) error {
  	var t time.Time
  	for {
  		// If we're beyond our timeout then return an error.
  		// This can only occur after we've attempted a flock once.
  		if t.IsZero() {
  			t = time.Now()
  		} else if timeout > 0 && time.Since(t) > timeout {
  			return ErrTimeout
  		}
  		flag := syscall.LOCK_SH
  		if exclusive {
  			flag = syscall.LOCK_EX
  		}
  
  		// Otherwise attempt to obtain an exclusive lock.
  		err := syscall.Flock(int(db.file.Fd()), flag|syscall.LOCK_NB)
  		if err == nil {
  			return nil
  		} else if err != syscall.EWOULDBLOCK {
  			return err
  		}
  
  		// Wait for a bit and try again.
  		time.Sleep(50 * time.Millisecond)
  	}
  }
docs: // flock acquires an advisory lock on a file descriptor.