JensRantil/go-sync

Go synchronisation primitives that support context.Context.

★ 4Forks 0GoGitHub ↗Compare

README

Build Status Go Report Card GoDoc

sync with Context

This is a small Golang library that tries to mimic (unless otherwise stated in doc) the behaviour of

  • sync.Mutex
  • sync.Cond

but adds context.Context to support deadlines.

So far very little time has been spent on performance here, but here are some crude benchmarks:

goos: darwin
goarch: amd64
pkg: github.com/JensRantil/sync-with-context
BenchmarkMutexLockUnlock-8              	25858257	        43.2 ns/op
BenchmarkStandardMutexLockUnlock-8      	122055702	         9.81 ns/op
BenchmarkMutexLockWithContextUnlock-8   	26493699	        43.7 ns/op
PASS
ok  	github.com/JensRantil/sync-with-context	4.665s

That is the sync.Mutex in standard library is about 77% faster than this mutex.

Benchmarking

If you are making changes to anything that could impact performance, please include the benchstat output in the pull request:

  1. go test -run='^$' -bench=. -count=10 > old.txt
  2. Make your change.
  3. go test -run='^$' -bench=. -count=10 > new.txt
  4. `go tool benchstat old.txt new.txt´

Credits

Initial development was sponsored by Tink.

Contributors

JensRantilbors[bot]

Issues