Documentation ¶
Overview ¶
Package sync implements primitives for syncronization between processes.
Index ¶
Constants ¶
const ( // FUTEX_PRIVATE_FLAG is used to optimize futex usage for process-private futexes. FUTEX_PRIVATE_FLAG = 128 // FUTEX_CLOCK_REALTIME is used to tell the kernel, that is must treat timeouts for // FUTEX_WAIT_BITSET, FUTEX_WAIT_REQUEUE_PI, and FUTEX_WAIT as an absolute time based on CLOCK_REALTIME FUTEX_CLOCK_REALTIME = 256 )
Variables ¶
This section is empty.
Functions ¶
func DestroyFutexMutex ¶
DestroyFutexMutex permanently removes mutex with the given name.
func DestroyMutex ¶
DestroyMutex permanently removes mutex with the given name.
func DestroySemaMutex ¶
DestroySemaMutex permanently removes mutex with the given name.
func DestroySpinMutex ¶
DestroySpinMutex removes a mutex object with the given name
Types ¶
type Futex ¶
type Futex struct {
// contains filtered or unexported fields
}
Futex is a linux ipc mechanism, which can be used to implement different synchronization objects.
type FutexMutex ¶
type FutexMutex struct {
// contains filtered or unexported fields
}
FutexMutex is a mutex based on linux futex object.
func NewFutexMutex ¶
NewFutexMutex creates a new futex-based mutex. This implementation is based on a paper 'Futexes Are Tricky' by Ulrich Drepper, this document can be found in 'docs' folder.
name - object name. flag - flag is a combination of open flags from 'os' package. perm - object's permission bits.
func (*FutexMutex) Close ¶
func (f *FutexMutex) Close() error
Close indicates, that the object is no longer in use, and that the underlying resources can be freed.
func (*FutexMutex) LockTimeout ¶
func (f *FutexMutex) LockTimeout(timeout time.Duration) bool
LockTimeout tries to lock the locker, waiting for not more, than timeout.
func (*FutexMutex) Unlock ¶
func (f *FutexMutex) Unlock()
Unlock releases the mutex. It panics on an error.
type IPCFutex ¶
type IPCFutex struct {
// contains filtered or unexported fields
}
IPCFutex is a linux futex, placed into a shared memory region.
func NewIPCFutex ¶
NewIPCFutex creates a new futex, placing it in a shared memory region with the given name.
name - shared memory region name. flag - flag is a combination of open flags from 'os' package. perm - object's permission bits. initial - initial futex value. it is set only if the futex was created.
func (*IPCFutex) Close ¶
Close indicates, that the object is no longer in use, and that the underlying resources can be freed.
type IPCLocker ¶
IPCLocker is a minimal interface, which must be satisfied by any synchronization primitive on any platform.
type SemaMutex ¶
type SemaMutex struct {
// contains filtered or unexported fields
}
SemaMutex is a semaphore-based mutex for unix.
func NewSemaMutex ¶
NewSemaMutex creates a new mutex.
func (*SemaMutex) LockTimeout ¶
LockTimeout tries to lock the locker, waiting for not more, than timeout.
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore is a sysV semaphore.
func NewSemaphore ¶
NewSemaphore creates a new sysV semaphore with the given name. It generates a key from the name, and then calls NewSemaphoreKey.
func NewSemaphoreKey ¶
NewSemaphoreKey creates a new sysV semaphore for the given key.
key - object key. each semaphore object is identifyed by a unique key. flag - flag is a combination of open flags from 'os' package. perm - object's permission bits. initial - this value will be added to the semaphore's value, if it was created.
func (*Semaphore) Add ¶
Add adds the given value to the semaphore's value. It locks, if the operation cannot be done immediately.
func (*Semaphore) AddTimeout ¶
AddTimeout add the given value to the semaphore's value. If the operation locks, it waits for not more, than timeout.
type SpinMutex ¶
type SpinMutex struct {
// contains filtered or unexported fields
}
SpinMutex is a synchronization object which performs busy wait loop.
func NewSpinMutex ¶
NewSpinMutex creates a new spin mutex.
name - object name. flag - flag is a combination of open flags from 'os' package. perm - object's permission bits.
func (*SpinMutex) Close ¶
Close indicates, that the object is no longer in use, and that the underlying resources can be freed.
func (SpinMutex) Lock ¶
func (spin SpinMutex) Lock()
Lock locks the mutex waiting in a busy loop if needed.