https://github.com/karpeleslab/idlock
Lock based on arbitrary numbers, in Go
https://github.com/karpeleslab/idlock
golang multithreading
Last synced: 12 months ago
JSON representation
Lock based on arbitrary numbers, in Go
- Host: GitHub
- URL: https://github.com/karpeleslab/idlock
- Owner: KarpelesLab
- License: bsd-3-clause
- Created: 2019-12-29T08:00:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-29T11:01:35.000Z (over 6 years ago)
- Last Synced: 2025-06-01T15:49:36.133Z (about 1 year ago)
- Topics: golang, multithreading
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://godoc.org/github.com/KarpelesLab/idlock)
# IntLock, etc
Very simple lock-by-id object for various purposes. Keep multiple locks under arbitrary ID values.
Example:
```Go
import (
"github.com/KarpelesLab/idlock"
"fmt"
)
func test(lk *idlock.IntLock, c chan struct{}) {
lk.Lock(2)
defer lk.Unlock(2)
fmt.Println("In test")
close(c)
}
func main() {
lk := idlock.NewInt()
lk.Lock(1, 2)
c := make(chan struct{})
go test(lk, c)
fmt.Println("Unlocking ...")
lk.Unlock(2)
<-c
lk.Unlock(1)
}
```