lock

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleTry

func ExampleTry()

ExampleTry test try lock

Types

type Mutex

type Mutex struct {
	sync.Mutex
}

Mutex 扩展一个Mutex结构

func (*Mutex) TryLock

func (m *Mutex) TryLock() bool

TryLock 尝试获取锁

type RecursiveMutex

type RecursiveMutex struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RecursiveMutex 包装一个Mutex,实现可重入, 即可重入锁(递归锁) 可重入锁主要用在线程需要多次进入临界区代码时,需要使用可重入锁,主要目的是为了避免死锁 临界区:一个被共享的资源

func (*RecursiveMutex) Lock

func (m *RecursiveMutex) Lock()

Lock 请求锁

func (*RecursiveMutex) Unlock

func (m *RecursiveMutex) Unlock()

Unlock 释放锁

type TokenRecursiveMutex

type TokenRecursiveMutex struct {
	sync.Mutex
	// contains filtered or unexported fields
}

TokenRecursiveMutex Token方式的递归锁

func (*TokenRecursiveMutex) Lock

func (m *TokenRecursiveMutex) Lock(token int64)

Lock 请求锁,需要传入token

func (*TokenRecursiveMutex) Unlock

func (m *TokenRecursiveMutex) Unlock(token int64)

Unlock 释放锁

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL