threadsafe

package
v1.154.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 1 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package threadsafe defines lock interfaces for building reusable, goroutine-safe data structures and helpers without hard-coding a concrete lock type.

It defines two lock interfaces:

  • Locker: the write-lock contract (`Lock` and `Unlock`), a defined type sharing the method set of sync.Locker.
  • RLocker: the read-lock contract (`RLock` and `RUnlock`) used by read/write synchronization patterns.

These interfaces are embedded or referenced by concurrent containers and utility types used across multiple goroutines.

Usage

See the examples in:

  • github.com/tecnickcom/nurago/pkg/threadsafe/tsmap
  • github.com/tecnickcom/nurago/pkg/threadsafe/tsslice

Read helpers in dependent packages accept RLocker, which a plain sync.Mutex does not satisfy (it has no `RLock`/`RUnlock`). This forces callers that need shared read access to supply an sync.RWMutex-like type at compile time, rather than serializing every read behind an exclusive lock. A sync.RWMutex satisfies both Locker and RLocker, so the same lock instance can drive read and write helpers.

These interfaces only describe the locking contract; they do not enforce it. All access to the protected data must funnel through the helper functions using the same lock instance, otherwise concurrent reads and writes are not safe.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

type Locker sync.Locker

Locker defines exclusive lock semantics with Lock and Unlock methods.

type RLocker

type RLocker interface {
	RLock()
	RUnlock()
}

RLocker defines shared read-lock semantics with RLock and RUnlock methods.

Directories

Path Synopsis
Package tsmap provides lock-aware generic helpers for operating on Go maps shared across multiple goroutines, keeping synchronization explicit at every call site.
Package tsmap provides lock-aware generic helpers for operating on Go maps shared across multiple goroutines, keeping synchronization explicit at every call site.
Package tsslice provides lock-aware generic helpers for operating on Go slices shared across multiple goroutines, keeping synchronization explicit around every access.
Package tsslice provides lock-aware generic helpers for operating on Go slices shared across multiple goroutines, keeping synchronization explicit around every access.

Jump to

Keyboard shortcuts

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