Introduction
Concurrency-safe basic types.
Use Scenarios:
gtype
is used very frequently and is applicable in any scenario requiring concurrency safety.
In common concurrency-safe scenarios, a variable of a basic type, especially a struct
containing several attributes, often uses mutex (read/write) locks or multiple (read/write) locks for safe management. However, in such usage, the operation performance of variables/struct/attributes
is very low, and the presence of the mutex lock mechanism often makes the operation quite complex, requiring careful maintenance of variable/attribute
concurrency safety control (especially (RW)Mutex
).
gtype
provides corresponding concurrency-safe data types for the most commonly used basic data types, making it easier to maintain variables/attributes in concurrency-safe scenarios. Developers no longer need to create and maintain cumbersome (RW)Mutex
in struct
. Since gtype
maintains concurrency safety for basic types, it mostly uses atomic
operations internally to maintain concurrency safety, often resulting in efficiency that is tens of times higher than (RW)Mutex
mutex locks.
Usage:
import "github.com/gogf/gf/v2/container/gtype"
Interface Documentation:
https://pkg.go.dev/github.com/gogf/gf/v2/container/gtype
Documents
📄️ Safe Type - Usage
Implement concurrent safe basic type operations using the gtype module in the GoFrame framework. The example code demonstrates how to create and operate on thread-safe basic types, such as increment and decrement operations on integer types, as well as JSON serialization and deserialization functions of gtype container types, helping developers manage data conveniently.
📄️ Safe Type - Performance
The performance benchmark results of safe types in the gtype package of the GoFrame framework are presented, analyzing the execution efficiency of different data type methods through detailed test data comparison, providing a reference for Go language developers to enhance data processing capabilities in concurrent programming.