From 0df091d0644f787577c2666a1be72eceed5531f1 Mon Sep 17 00:00:00 2001 From: geolffreym Date: Fri, 10 Jun 2022 14:16:52 -0600 Subject: [PATCH] synchronization/read-write-lock: peer conenction router example implementation --- synchronization/read-write-lock.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/synchronization/read-write-lock.md b/synchronization/read-write-lock.md index 2a94a59..fbc6db2 100644 --- a/synchronization/read-write-lock.md +++ b/synchronization/read-write-lock.md @@ -46,7 +46,7 @@ func (r *Router) Query(socket Socket) *Peer { // Add create new socket connection association func (r *Router) Add(peer *Peer) { - // Lock write/read table while add operation + // Lock write table while add operation // A blocked Lock call excludes new readers from acquiring the lock. r.RWMutex.Lock() defer r.RWMutex.Unlock() @@ -55,7 +55,7 @@ func (r *Router) Add(peer *Peer) { // Delete removes a connection from router func (r *Router) Delete(peer *Peer) { - // Lock write/read table while delete operation + // Lock write table while delete operation // A blocked Lock call excludes new readers from acquiring the lock. r.RWMutex.Lock() defer r.RWMutex.Unlock() @@ -100,10 +100,10 @@ go func(r *Router){ go func(r *Router){ // ...some logic here // reading operation 1 - connection := router.Query("192.168.1.1:8080") + connection := r.Query("192.168.1.1:8080") //... more code here // reading operation 2 - otherQuery:= router.Query("192.168.1.1:8081") + otherQuery:= r.Query("192.168.1.1:8081") // read locks are like counters.. until counter = 0 Write can be acquired }(router)