golock

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoLock

type GoLock struct {
	Mutex  sync.Mutex   // 读锁时不能写,写锁时不能读取
	MuteRW sync.RWMutex //读写互斥锁,并发读取,单一写入。读多写少性能会好
}

RWMutex 也称为读写互斥锁,读写互斥锁就是读取/写入互相排斥的锁。它可以由任意数量的读取操作的 goroutine 或单个写入操作的 goroutine 持有。 读写互斥锁 RWMutex 类型有五个方法,Lock,Unlock,Rlock,RUnlock 和 RLocker。其中,RLocker 返回一个 Locker 接口, 该接口通过调用 rw.RLock 和 rw.RUnlock 来实现 Lock 和 Unlock 方法。 不能拷贝锁

func New

func New() *GoLock

func (*GoLock) GoRLock

func (g *GoLock) GoRLock(fn func())

加读锁

func (*GoLock) GoWLock

func (g *GoLock) GoWLock(fn func())

加写锁

func (*GoLock) Lock

func (g *GoLock) Lock(fn func(parameters ...any), parameters ...any)

共享内存加锁

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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