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:
parent
097cfd0579
commit
17e9b60552
1 changed files with 3 additions and 3 deletions
|
@ -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)
|
||||
|
||||
```
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue