Documentation
¶
Overview ¶
Package threadsafe solves a small but important design problem in concurrent Go code: how to write reusable, goroutine-safe data structures and helpers without hard-coding a concrete lock type everywhere.
Problem ¶
Many concurrency-aware packages need only a tiny synchronization contract (`Lock`/`Unlock` or `RLock`/`RUnlock`), but directly depending on concrete types like sync.Mutex or sync.RWMutex makes code less composable and harder to test. A package-level interface abstraction allows callers and dependent packages to share thread-safety behavior while keeping implementation details flexible.
What This Package Provides ¶
This package intentionally stays minimal and defines two lock interfaces:
- Locker: the write-lock contract (`Lock` and `Unlock`), aliased from sync.Locker.
- RLocker: the read-lock contract (`RLock` and `RUnlock`) used by read/write synchronization patterns.
These interfaces are intended to be embedded or referenced by concurrent containers and utility types that must be safely used across multiple goroutines.
Why It Matters ¶
- Decouples concurrency contracts from concrete lock implementations.
- Improves reuse across packages that need the same minimal synchronization surface.
- Simplifies testing and composition when custom lock wrappers are used.
Usage ¶
See the examples in:
- github.com/tecnickcom/gogen/pkg/tsmap
- github.com/tecnickcom/gogen/pkg/tsslice
Those packages demonstrate how these interfaces are used to build practical, thread-safe containers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package tsmap solves the common concurrency problem of safely operating on Go maps shared across multiple goroutines without repeatedly writing lock/unlock boilerplate at every call site.
|
Package tsmap solves the common concurrency problem of safely operating on Go maps shared across multiple goroutines without repeatedly writing lock/unlock boilerplate at every call site. |
|
Package tsslice solves the common concurrency problem of safely operating on Go slices shared across multiple goroutines without repeating lock boilerplate around every access.
|
Package tsslice solves the common concurrency problem of safely operating on Go slices shared across multiple goroutines without repeating lock boilerplate around every access. |