https://github.com/bry00/fmutex
Simple golang package designated to provide simple mutex locking, based on filesystem hard links functionality.
https://github.com/bry00/fmutex
distributed-locking golang mutex mutex-synchronisation
Last synced: 29 days ago
JSON representation
Simple golang package designated to provide simple mutex locking, based on filesystem hard links functionality.
- Host: GitHub
- URL: https://github.com/bry00/fmutex
- Owner: bry00
- License: mit
- Created: 2021-01-11T22:36:01.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-21T18:23:54.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T10:15:52.327Z (over 1 year ago)
- Topics: distributed-locking, golang, mutex, mutex-synchronisation
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fmutex/mutex
Package mutext is designated to provide simple mutex locking
based on filesystem hard links functionality.
Given filesystem link function must fail, if target file already exists,
which is true for the Linux and MacOS platforms.
The module is designated to be used in distributed environment, using common
resource of the filesystem, for example for synchnonization during
initialization of K8s pods.
Related sample program `fmutex` can be used as a mutex utility for shell scripts.
## Getting started
To install run:
```console
go get github.com/bry00/fmutex
```
For usage example see the source of the sample `fmutex utility`: [main.go](main.go)
For a quick start, below is very simple usage sample:
```go
package main
import (
"log"
"os"
"github.com/bry00/fmutex/mutex"
)
const MUTEX_ID = "sample-mutex"
const MUTEX_ROOT := "/tmp"
func main() {
mx, err := mutex.NewMutex(MUTEX_ROOT, MUTEX_ID)
if err != nil {
log.Fatalf("cannot create the mutex: %v", err)
}
defer mx.Unlock()
mx.Lock()
// Do something that needs to be synced
fmt.Println("DONE")
}
```
## License
The package is released under [the MIT license](LICENSE).