trylock

package module
v0.0.0-...-003af2f Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 0 Imported by: 0

README

trylock

Goproxy.cn

实现go版本的的 try lock --- 排外锁。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Trylock

type Trylock struct {
	// contains filtered or unexported fields
}

排外锁的原理很简单,使用一个channel,如果能获得这个channel就是说明,可以或得到锁,不能就是不能返回false即可。

func NewTrylock

func NewTrylock() *Trylock

func (*Trylock) Lock

func (t *Trylock) Lock() bool

如果可以把数据取出来,那么就是证明是true,否则就是false

func (*Trylock) Unlock

func (t *Trylock) Unlock()

为了解锁,就是把这个channle重新重入数据即可。

Jump to

Keyboard shortcuts

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