Last active
March 10, 2022 16:37
-
-
Save prembhaskal/b208de5df6677aa5d40e80d95827ff85 to your computer and use it in GitHub Desktop.
testing reference pointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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