gls - Goroutine 本地存储库


GPL
跨平台
Google Go

软件简介

golang 语言目前唯一的高性能 goroutine local storage 实现,每秒可以完成数百万次Get/Set。

Operate Performance
Benchmark_Goid 5.30 ns/op
Benchmark_Set 271 ns/op
Benchmark_Get 155 ns/op
Benchmark_Set_4Threads 129 ns/op
Benchmark_Get_4Threads 58.6 ns/op

使用起来极为简单:

import "github.com/yyzybb537/gls"

// 设置协程局部变量
gls.Set("Value", 1)

// 获取协程局部变量
var i int = gls.Get("Value").(int)

// 协程退出时使用Cleanup清除相关资源
defer Cleanup()