mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-04-30 12:00:39 +00:00
8c7017a99d
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5" - Update version.txt from 4.29 → .30 (automated by Makefile)
1.3 KiB
1.3 KiB
obilua.Mutex: Thread-Safe Synchronization in Lua via Go's sync.Mutex
This package exposes Go’s sync.Mutex to the Lua environment using gopher-lua, enabling safe concurrent access from Lua scripts.
Key Features
- Custom userdata type: Registers a new metatable
"Mutex"in the Lua state. - Constructor function:
Mutex.new() → mutex userdata
Creates and returns a new Go-backed mutex instance.
- Instance methods:
mutex:lock()— Acquires the lock (blocks until available).mutex:unlock()— Releases the lock.
- Type safety: Validates that only valid mutex userdatas are passed to
lock/unlock. - Integration: Designed for embedding Lua in Go applications requiring synchronization (e.g., multi-threaded scripting).
Usage Example
local m = Mutex.new()
m:lock() -- Acquire lock (safe across goroutines)
-- critical section
m:unlock()
Implementation Notes
- Mutex state is stored in a Go
*sync.Mutexinside Lua userdata. - No reference counting or finalizers — user must manually manage lock/unlock lifecycle to avoid deadlocks.
- Thread-safe from Go side only; Lua calls must respect goroutine safety (e.g., avoid calling from multiple VMs concurrently).