Much appreciated for all the great advises from everyone. Or to be more precise: it is crucial you load wait before notify and the > check for equality can only happen if the routine "caught up". Also, your > proof must hold if you remove the fast-path check in line 522. >
Why is it crucial to load wait before notify? May be I missed where wait is updated after notify to create happen-before relationship for the loads ordering to matter. Also, the fast-path you mention, should the proof be harder to produce if we introduce fast-path, as opposed to not having it in the first place. I didn't mean to imply that data races are OK. I meant that when > using condition variables, you have to be aware of the race conditions > between Wait and Signal/Broadcast, and you have to mitigate those race > conditions through correct use of the Locker associated with the > condition variable. These race conditions are not data race > conditions, they are rather logical race conditions, in the sense that > if you do not correctly use the Locker then your goroutines can indeed > block forever in Wait. > As I become aware of this race condition between waiters and signalers, is it enough to make sure that all increments to wait happen-before the signal call to avoid being blocked forever? You are describing the possible race in terms of the runtime code, > which is the wrong level. > May be I am, but only if the documentation of higher level code provides sufficient information about stuff like possible races above. Most of the time when I learn about synchronization, I am forced to fallback to runtime code to make sense of hard-to-understand higher interfaces. Please don't misunderstand me, I am fully aware that good documentation for all levels of readers is very very hard to write so I absolutely don't blame anyone at all. -- 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.