From ec2834463c761dfdccda4da78a3fb382cae14869 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 24 Dec 2018 15:22:17 +1100 Subject: [PATCH] Add some tip for sync.RWMutex --- categories/go.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/categories/go.md b/categories/go.md index bcaaa74..c6aa6cc 100644 --- a/categories/go.md +++ b/categories/go.md @@ -58,16 +58,24 @@ ch := make(chan Task, 3) ## Sync -- atomic -- Mutex +### atomic +### Mutex - sync.Mutex() - mutex.Lock() - mutx.Unlock() -- string literals +### RWMutex + > A RWMutex is a reader/writer mutual exclusion lock. The lock can be held by an arbitrary number of readers or a single writer. The zero value for a RWMutex is an unlocked mutex. - \`aaa bbb ccc\` -- panic / recover -- `sync.Map` is concurrent/ thread safe `map`, normal `map` isn't +In other words, readers don't have to wait for each other. They only have to wait for writers holding the lock. + +### string literals + +```go + `aaa bbb ccc` +``` +### panic / recover + +### `sync.Map` is concurrent/ thread safe `map`, normal `map` isn't ```go m := new(sync.Map)