An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

[![GoDoc](https://godoc.org/github.com/KarpelesLab/idlock?status.svg)](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)
}
```