mutualexclusion

package
v0.0.0-...-8c27e12 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const OTHERS = -1

OTHERS 表示信息接收方为其他所有 process

Variables

This section is empty.

Functions

This section is empty.

Types

type Clock

type Clock interface {
	// Update 根据输入参数更新自身的值
	Update(int)
	// Tick 时钟跳动一次,并返回最新的时间值
	Tick() int
	// Now 返回当前的时间值
	Now() int
}

Clock 是系统的逻辑时钟接口

type Less

type Less interface {
	// Less 比较两个接口的值
	Less(interface{}) bool
	// String() 输出内容
	String() string
}

Less 是 rpq 元素中的主要成分

type Process

type Process interface {
	// Request 会申请占用资源
	// 如果上次 Request 后,还没有占用并释放资源,会发生阻塞
	// 非线程安全
	Request()
}

Process 是进程的接口

type ReceivedTime

type ReceivedTime interface {
	// Update 更新从 process 接收到的最新时间
	Update(process, time int)
	// Min 返回从各个 process 接收时间的最小值
	Min() int
}

ReceivedTime 是最新接受时间的操作接口 因为 Rule5(ii) 需要用到最小的接受时间

type RequestQueue

type RequestQueue interface {
	// Min 返回最小的 Timestamp 值
	Min() Less
	// Push 把元素加入 RequestQueue 中
	Push(Less)
	// Remove 在 RequestQueue 中删除 Less
	Remove(Less)
	// String 输出 RequestQueue 的细节
	String() string
}

RequestQueue 提供了操作 request queue 的接口

type Resource

type Resource interface {
	// Occupy 表示占用资源
	Occupy(Timestamp)
	// Release 表示释放资源
	Release(Timestamp)
}

Resource 是 Process 占用资源的接口

type Timestamp

type Timestamp interface {
	// Less 比较两个 Timestamp 的大小
	Less(interface{}) bool
	// Equal 判断两个 Timestamp 是否相等
	IsEqual(interface{}) bool
	// IsBefore 在比较同一个 clock 的时间,所以,不需要 process
	IsBefore(int) bool
	// String 输出 Timestamp 的内容
	String() string
}

Timestamp 是用于全局排序的接口

Jump to

Keyboard shortcuts

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