go RWMutex
tags: learning go programming
content
-
for normal mutex, it’s like a talking pillow, whoever has it has the right to execute code
-
it’s good for writing data, but not so good for reading data
-
for read intensive processes, we want different threads to be able to read at the same time, and keep only one thread able to write
-
and when there’s data-write, we wanna block data-read
- this is where
RWMutexcomes in
- this is where
-
if a reader is reading while a writer is writing, it causes data race
-
when a go routine has
mutex.RLock(), it means “i’m a reader, other readers feel free to jump in when i’m reading, but writers hold up”