Skip to content

barryz/spinlock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spinlock

Go Report Card GoDoc Build Status Apache 2 licensed

Spinlock is a spin-lock implementation written by Go.

Usage

import "github.com/barryz/spinlock"

lock := spinlock.New()

lock.Lock()     // Try to acquire the lock.
lock.Unlock()   // Release the lock.
lock.String()   // Print the lock status.

// embedding
type Foo struct {
    lock *spinlock.SpinLock // always use pointer to avoid copy
}

Benchmark:

  • Go 1.11.0
  • OS X 10.13.6
BenchmarkSpinLock       100000000               14.5 ns/op             0 B/op          0 allocs/op 
BenchmarkSpinLock-2     100000000               14.4 ns/op             0 B/op          0 allocs/op
BenchmarkSpinLock-4     100000000               14.2 ns/op             0 B/op          0 allocs/op
BenchmarkMutex          100000000               16.1 ns/op             0 B/op          0 allocs/op
BenchmarkMutex-2        100000000               16.3 ns/op             0 B/op          0 allocs/op
BenchmarkMutex-4        100000000               18.1 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexW       50000000                33.5 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexW-2     50000000                33.4 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexW-4     50000000                33.5 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexR       100000000               15.7 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexR-2     100000000               15.9 ns/op             0 B/op          0 allocs/op
BenchmarkRWMutexR-4     100000000               18.1 ns/op             0 B/op          0 allocs/op

About

Spinlock is a spin-lock go language implementation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages