As I understood it: Normally, when two (or more) goroutines call RLock, they can acquire the read lock simultaneously without problem. But, you cannot assume that this property always holds (see Caleb's example). If your algorithm relies on two goroutines holding the read lock at the same time, your program can deadlock.
On Monday, October 31, 2016 at 1:35:00 PM UTC+1, seaf...@gmail.com wrote: > > I cannot still get it! > Could you explain it to me? > Thanks ahead > > 在 2016年10月4日星期二 UTC+8上午5:28:11,Roberto Zanotto写道: >> >> I get it now. Thanks for your time. >> >> On Monday, October 3, 2016 at 10:55:34 PM UTC+2, Caleb Spare wrote: >>> >>> It's explained in the text afterwards: >>> >>> "This is to ensure that the lock eventually becomes available; a >>> blocked Lock call excludes new readers from acquiring the lock." >>> >>> So if you RLock and then another goroutine tries to Lock, you might >>> not be able to RLock again until the first read lock is RUnlocked (and >>> after the Lock+Unlock). >>> >>> -Caleb >>> >>> On Mon, Oct 3, 2016 at 1:50 PM, Roberto Zanotto <roby...@gmail.com> >>> wrote: >>> > Hi everyone. >>> > >>> > I thought I understood clearly how an RWMutex is supposed to work, but >>> the >>> > documentation is giving me some troubles. >>> > It says: "The lock can be held by an arbitrary number of readers" >>> > which is fine by me, but then the following statement seems to >>> contradict >>> > it: >>> > "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.". >>> > Am I missing something? >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> Groups >>> > "golang-nuts" group. >>> > To unsubscribe from this group and stop receiving emails from it, send >>> an >>> > email to golang-nuts...@googlegroups.com. >>> > For more options, visit https://groups.google.com/d/optout. >>> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.