-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdoc.go
21 lines (14 loc) · 1.23 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
Package `stl` provides multiple atomic dynamic shared/exclusive locks, based of Software Transactional Memory (STM) concurrency control mechanism. In addition `stl` locks can take `context.Context` that allows to cancel or set a deadline for such locks.
Locks are fast and lightweight. The implementation requires only one `mutex` and one `channel` per vault (a set of locks with any number of resources).
`stl` can lock any number of resources atomically without a deadlock. Each resource can be locked in `exclusive` manner (only one locker can lock such resource at the same time) or in `shared` manner (all 'shared' lockers can lock such resource at the same time, a locker that wants to lock such resource 'exclusively' will wait them to finish).
You can also combine `shared` and `exclusive` resources while building a transaction or transactional locker:
// A vault that holds all locked resources.
v := stl.NewVault()
// ...
locker := stl.New().Exclusive("terminal").Shared("network").ToLocker(v)
locker.Lock()
defer locker.Unlock()
It's also possible to call `locker.LockWithContext(ctx)` if you want to be able to cancel or set a deadline for locking operation. This will add additional flexibility to your applications.
*/
package stl