Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: deemphasize goroutines in RWMutex documentation #41555

Closed
bcmills opened this issue Sep 22, 2020 · 3 comments
Closed

sync: deemphasize goroutines in RWMutex documentation #41555

bcmills opened this issue Sep 22, 2020 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Sep 22, 2020

sync.RWMutex performs no goroutine-specific accounting (see also #9201) and cannot be locked reentrantly.

Despite the fact that a sync.RWMutex is not held by a specific goroutine, the documentation for the RWMutex type is currently phrased in terms of goroutines holding the lock (emphasis mine):

If a goroutine holds a RWMutex for reading and another goroutine might call Lock, no goroutine should expect to be able to acquire a read lock until the initial read lock is released. In particular, this prohibits recursive read locking. This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock.

This stands in contrast to the documentation for the Unlock method, which states more clearly:

As with Mutexes, a locked RWMutex is not associated with a particular goroutine. One goroutine may RLock (Lock) a RWMutex and then arrange for another goroutine to RUnlock (Unlock) it.

The type-level documentation should be rewritten so that it does not imply that the existing holder of the RWMutex is “a goroutine”.

@bcmills bcmills added Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Sep 22, 2020
@bcmills bcmills added this to the Backlog milestone Sep 22, 2020
@bcmills
Copy link
Contributor Author

bcmills commented Sep 22, 2020

Also, the documentation for the RLock method currently states (emphasis mine):

It should not be used for recursive read locking; a blocked Lock call excludes new readers from acquiring the lock.

The use of “should” implies that the RLock method potentially could be used for recursive read-locking, which is not actually the case.

@gopherbot
Copy link

Change https://golang.org/cl/256737 mentions this issue: sync: deemphasize goroutines in RWMutex documentation

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 7, 2022
qiulaidongfeng added a commit to qiulaidongfeng/go that referenced this issue Aug 12, 2023
Fixes: golang#41555
Change-Id: I46b9535b1687d481d2ac76296e8ba7de26d6e2e2
@gopherbot
Copy link

Change https://go.dev/cl/518859 mentions this issue: sync: deemphasize goroutines in RWMutex documentation

qiulaidongfeng added a commit to qiulaidongfeng/go that referenced this issue Aug 15, 2023
Fixes golang#41555
Change-Id: I46b9535b1687d481d2ac76296e8ba7de26d6e2e2
@dmitshur dmitshur modified the milestones: Backlog, Go1.22 Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants