1
0
Fork 0
mirror of https://github.com/tmrts/go-patterns.git synced 2025-04-02 20:56:12 +03:00

Update read_write_lock.md

This commit is contained in:
Geolffrey Mena 2022-06-10 20:53:14 -06:00 committed by GitHub
parent 097cfd0579
commit 17e9b60552
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,8 +49,8 @@ func (r *Router) Add(peer *Peer) {
// Lock write table while add operation
// A blocked Lock call excludes new readers from acquiring the lock.
r.RWMutex.Lock()
defer r.RWMutex.Unlock()
r.table[peer.Socket()] = peer
r.RWMutex.Unlock()
}
// Delete removes a connection from router
@ -58,8 +58,8 @@ func (r *Router) Delete(peer *Peer) {
// Lock write table while delete operation
// A blocked Lock call excludes new readers from acquiring the lock.
r.RWMutex.Lock()
defer r.RWMutex.Unlock()
delete(r.table, peer.Socket())
r.RWMutex.Unlock()
}
```
@ -107,4 +107,4 @@ go func(r *Router){
// read locks are like counters.. until counter = 0 Write can be acquired
}(router)
```
```