shad-go/keylock/README.md

21 lines
936 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# keylock
Напишите примитив синхронизации, позволяющий "лочить" строки из множества.
```go
package keylock
type KeyLock interface {
// LockKeys locks all keys from provided set.
//
// Upon successful completion, function guarantees that no other call with intersecting set of keys
// will finish, until unlock() is called.
//
// If cancel channel is closed, function stops trying to lock received keys and returns immediately
LockKeys(keys []string, cancel <-chan struct{}) (canceled bool, unlock func())
}
```
Реализация не должна содержать busy wait. То есть, если вызов LockKeys не может выполниться,
потому что какие-то из ключей залочены другими горутинами, то текущая горутина
должна засыпать.