Skip to content

proposal: sync: Add UnlockToRLock() to RWMutex #38891

@pjebs

Description

@pjebs

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:

  1. Aquire a Lock
  2. Do something with the lock.
  3. Release the Lock.
  4. Immediately acquire RLock.
  5. Do something with read lock.
  6. Release the RUnlock.

The objective is:

  1. Increase throughput by allowing more goroutines wishing to Read to be able to do so. AND
  2. 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:

  1. Reduce throughput by keeping Step 1-6 inside a Lock OR
  2. 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")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions