From caa0429d0673bc572de8edbf7adf3b1122c3e4e7 Mon Sep 17 00:00:00 2001 From: qichengzx Date: Tue, 9 Oct 2018 12:27:10 +0800 Subject: [PATCH] #365 --- ch4-rpc/ch4-03-netrpc-hack.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ch4-rpc/ch4-03-netrpc-hack.md b/ch4-rpc/ch4-03-netrpc-hack.md index 3630fed..b66985a 100644 --- a/ch4-rpc/ch4-03-netrpc-hack.md +++ b/ch4-rpc/ch4-03-netrpc-hack.md @@ -96,8 +96,8 @@ func NewKVStoreService() *KVStoreService { ```go func (p *KVStoreService) Get(key string, value *string) error { - p.Lock() - defer p.Unlock() + p.mu.Lock() + defer p.mu.Unlock() if v, ok := p.m[key]; ok { *value = v @@ -108,8 +108,8 @@ func (p *KVStoreService) Get(key string, value *string) error { } func (p *KVStoreService) Set(kv [2]string, reply *struct{}) error { - p.Lock() - defer p.Unlock() + p.mu.Lock() + defer p.mu.Unlock() key, value := kv[0], kv[1] @@ -133,9 +133,9 @@ func (p *KVStoreService) Watch(timeoutSecond int, keyChanged *string) error { id := fmt.Sprintf("watch-%s-%03d", time.Now(), rand.Int()) ch := make(chan string, 10) // buffered - p.Lock() + p.mu.Lock() p.filter[id] = func(key string) { ch <- key } - p.Unlock() + p.mu.Unlock() select { case <-time.After(time.Duration(timeoutSecond) * time.Second):