https://github.com/aprimadi/namespace-lock
Namespace lock implementation in Go
https://github.com/aprimadi/namespace-lock
distributed-systems lock locking
Last synced: about 1 year ago
JSON representation
Namespace lock implementation in Go
- Host: GitHub
- URL: https://github.com/aprimadi/namespace-lock
- Owner: aprimadi
- License: mit
- Created: 2020-08-12T10:45:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-12T10:45:26.000Z (over 5 years ago)
- Last Synced: 2025-04-24T23:15:23.586Z (about 1 year ago)
- Topics: distributed-systems, lock, locking
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Namespace Lock
==============
Namespace locking implementation in Go. A namespace is a hierarchical resource
structure that can be thought of as a tree similar to directory structure in
Unix system.
## Usage
```go
package main
import (
"github.com/aprimadi/namespace-lock"
)
func main() {
lock := nlock.NewNamespaceLock()
go func() {
// Acquire a read lock on "/a", "/a/b"
lock.RLock("/a/b")
// ... do things
// Release read locks "/a" and "/a/b"
lock.RUnlock("/a/b")
}()
go func() {
// Acquire a read lock on "/a", "/a/b" and a write lock on "/a/b/c"
lock.Lock("/a/b/c")
// ... do things
// Release read locks "/a", "/a/b" and write lock "/a/b/c"
lock.Unlock("/a/b/c")
}()
}
```