bschofield commented on pull request #663:
URL: https://github.com/apache/pulsar-client-go/pull/663#issuecomment-963931326
Thanks for taking a look at this, @BewareMyPower and @cckellogg!
> So I think c.Lock() is the same as c.cond.L.Lock().
I'm pretty sure that's not the case. If we take a look at the definition of
the connection type:
```go
type connection struct {
sync.Mutex
cond *sync.Cond
[...]
```
...then we can see that `connection` struct is built out of a `sync.Mutex`
using struct composition. That means that calls to `c.Lock()` are calling the
`sync.Mutex` which is part of the `connection` struct itself.
If we next take a look at the definition of `sync.Cond` we see:
```go
type Cond struct {
noCopy noCopy
// L is held while observing or changing the condition
L Locker
[...]
```
(where `Locker` is go's interface type for a `sync.Mutex`). So these are two
separate locks: they are not the same.
Another way we can convince ourselves of this is by noting that it is
forbidden to copy a `sync.Mutex`, you have to take pointers to it. Since the
struct composition on `connection` does not use a pointer type, there would be
no way to alias the mutex inside `cond` to the mutex on `connection`. They must
be different things.
--
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]