-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Milestone
Description
There is a scenario that can't be done efficiently (or at all) from outside sync package.
This is with regards to RWMutex
If you have an operation that has a well delineated "write" portion and "read" portion:
- Aquire a Lock
- Do something with the lock.
- Release the Lock.
- Immediately acquire RLock.
- Do something with read lock.
- Release the RUnlock.
The objective is:
- Increase throughput by allowing more goroutines wishing to Read to be able to do so. AND
- Prevent another goroutine that wants to Lock from interjecting between steps 3 and 4 above.
My proposal is a function called UnlockToRLock()
that is simple to implement from inside sync
package that covers the scenario above.
The alternative is:
- Reduce throughput by keeping Step 1-6 inside a Lock OR
Accept a goroutine that wants to acquire lock interjecting between Step 3&4(the scenario assumes an operation where the "read" portion must follow the "write" portion, and it is not correct for another goroutine to potentially interfere before the "read")
networkimprov, pjebs and navytuxdavecheney, seankhliao, as, cristaloleg and florianl