The lockfile package exports a LockFile class which provides a simple API for locking files.