Skip to content

Instantly share code, notes, and snippets.

@prembhaskal
Last active March 10, 2022 16:37
Show Gist options
  • Save prembhaskal/b208de5df6677aa5d40e80d95827ff85 to your computer and use it in GitHub Desktop.
Save prembhaskal/b208de5df6677aa5d40e80d95827ff85 to your computer and use it in GitHub Desktop.
testing reference pointer
package parallel
import "sync"
type client struct {
val int
}
func (c *client) Add(x int) int {
return c.val + x
}
type library struct {
c *client
mx sync.Mutex
}
func NewLibrary() *library {
c := &client{
val: 0,
}
return &library{
c: c,
}
}
func (l *library) C() *client {
return l.c
}
func (l *library) UpdateClient() {
l.mx.Lock()
defer l.mx.Unlock()
newVal := l.c.val + 1
l.c = &client{newVal}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment