Replies: 1 comment
|
We already have an RW-lock implementation inside I did not yet look at the implementation you propose adding here. Could you please summarize the differences between that and the semaphore-based implementation? In general, I'm somewhat wary about adding even more lock-variants to std. We already have |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
stdhasMutexandKeyedMutex, but nothing for shared/exclusive locking. The need shows up whenever many fibers read state that gets replaced once in a while: config reload, cache refresh, swapping a connection after re-auth.Mutexworks but serializes the readers against each other for no reason. The usual workaround isSemaphore(n)where a reader takes 1 permit and a writer takes all n, which forces an arbitrary bound on concurrent readers and makes writer acquisition O(n).Proposed API, following
Mutex:Semantics:
Mutex:writeLockinsidereadLock(or any nesting that waits on itself) deadlocksPrior art:
java.util.concurrent.locks.ReentrantReadWriteLock, ZIO'sTReentrantLock, andReadWriteRefin evolution-gaming/cats-helper, which has these exact semantics on plainConcurrentand has been running in production for a few years. I'd be happy to contribute the implementation adapted to std conventions. It could probably sit on top ofLockQueue, whichMutexandKeyedMutexalready share.Open questions:
ReadWriteLockvs something shorterMutexReadWriteRef, the wayAtomicCellpairs a value withMutex)? The lock alone seems like the right primitive to start with.All reactions