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: confusing documentation for RWMutex #19460
Comments
Pedantically, you say "subsequent calls to |
Oh? Looks like I'm still confused then. 😛 rw := sync.RWMutex{}
rw.RLock()
go rw.Lock()
rw.RLock() // :( You would always* end up with a deadlock (*assuming 'favourable' scheduling) |
I'm sorry, I misread your comment. I think you're right. |
CL https://golang.org/cl/45697 mentions this issue. |
This was already fixed once in #15418 by b3f98d7. I just tried to say more in https://golang.org/cl/45697 but it's unclear how much better my updated text is. I'll let @ianlancetaylor or @dvyukov decide. |
Are you sure they are contradicting? What exactly is the contradiction? |
The contradiction is only in a world with no goroutines calling Lock. It says "an arbitrary number of readers" or "a single writer". The arbitrary number of readers part is actually true if there's no goroutine ever calling Lock. Then anybody's free to call RLock without fear of deadlocks. The deadlock only happens if anybody's calling Lock. The CL I sent above the words:
|
@bradfitz right |
👍, though I still think
|
RLock may block until (at least for the "is trying to lock for writing" case) |
I've added a small note to the |
sync#RWMutex
The third paragraph "If a goroutine holds a RWMutex for reading, it must not expect this or any other goroutine to be able to also take the read lock until the first read lock is released." appears to contradict the first paragraph "The lock can be held by an arbitrary number of readers or a single writer."
After reading #7576 I think I understand this to mean that subsequent calls to
RWMutex.RLock()
will block if a call toRWMutex.Lock()
has taken place (even if the write lock is currently not held), however that is not apparent from the rest of the documentation.If this is the case can the forward for
RWLock
and the documentation forRWLock.RLock
be updated to match please?The text was updated successfully, but these errors were encountered: