werf / lockgate

Lockgate is a cross-platform distributed locking library for Go. Supports distributed locks backed by Kubernetes or HTTP lock server. Supports conventional OS file locks.
Apache License 2.0
256 stars 15 forks source link

Semaphore #34

Open satunin opened 3 years ago

satunin commented 3 years ago

Hi. Can i use this library like a semaphore. For example Acquire() can return SharedHoldersCount, not only LockHandle

distorhead commented 3 years ago

I think it is currently not possible to make shared holders count available publicly in the LockHandle (or as a separate return value), because this counter could change in any moment leaving a user of LockHandle with incorrect count number. Semaphore support should be added directly into the core of the library.

Semaphore could be implemented using mutex though. But it is up to you to make counter shared between multiple processes using some storage.