Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock represents a lock of the semaphore. After the lock is not needed any more it should be released.
type Simple ¶
type Simple struct {
// contains filtered or unexported fields
}
Simple provides a way to lock concurrent access to a resource. It only allows one caller to gain access at a time.
func (*Simple) Acquire ¶
Acquire acquires a Lock, blocking until the previous ticket is released. Ticket needs to be discarded after the call to Acquire. The Lock has to be supplied to Release after it is not needed anymore and discarded afterwards. Acquire is safe for concurrent use.
func (*Simple) Enqueue ¶
Enqueue reserves the next place in the queue and returns a Ticket used to acquire access to the Lock when it's the callers turn. The Ticket has to be supplied to Acquire and discarded afterwards. Enqueue is not safe for concurrent use.
Example ¶
ExampleSimple demonstrates how different goroutines can be orchestrated to acquire locks in the same order as the tickets enqueued in the semaphore.
Output: routine 2: try acquiring the lock routine 1: try acquiring the lock routine 1: acquired the lock routine 2: acquired the lock