BewareMyPower commented on pull request #663:
URL: https://github.com/apache/pulsar-client-go/pull/663#issuecomment-963745752


   I agree that we should call `c.Broadcast()` after `c.Wait()`, but the code 
here is not like the example in 
https://stackoverflow.com/questions/36857167/how-to-correctly-use-sync-cond/42772799#42772799.
   
   ```go
       m := &sync.Mutex{}
       c := sync.NewCond(m)
       m.Lock()
       go func() {
           m.Lock() // Wait for c.Wait()
           c.Broadcast()
           m.Unlock()
       }()
       c.Wait() // Unlocks m, waits, then locks m again
       m.Unlock()
   ```
   
   Because in that example, the `m.Lock()` has already been called before the 
goroutine is executed. So `c.Broadcast()` won't be called before `c.Wait()` 
releases the mutex internally. However, for the code here, how could you ensure 
that when `changeState` is called, the lock has already been acquired in 
`waitUntilReady`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to