Skip to content
/ fmutex Public

Simple golang package designated to provide simple mutex locking, based on filesystem hard links functionality.

License

Notifications You must be signed in to change notification settings

bry00/fmutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

go get github.com/bry00/fmutex

For usage example see the source of the sample fmutex utility: main.go

For a quick start, below is very simple usage sample:

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.

About

Simple golang package designated to provide simple mutex locking, based on filesystem hard links functionality.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages