Skip to content

Commit 1fd22f6

Browse files
committed
update go trap
1 parent 5e2bfc9 commit 1fd22f6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

go-note/tricks.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Go 无法修改值为结构体的map
128128
129129
不要并发读写map,可能导致程序崩溃
130130
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
131-
如果多个 goroutine 并发对 map 进行读写,必须要同步
131+
如果多个 goroutine 并发对 map 进行读写,必须要同步,否则可能导致进程退出
132132

133133
.. code-block:: go
134134
@@ -137,13 +137,13 @@ Go 无法修改值为结构体的map
137137
sync.RWMutex
138138
m map[string]int
139139
}{m: make(map[string]int)}
140-
counter.RLock()
141140
141+
counter.RLock() // locks for reading
142142
n := counter.m["some_key"]
143143
counter.RUnlock()
144144
fmt.Println("some_key:", n)
145145
146-
counter.Lock()
146+
counter.Lock() // locks for writing
147147
counter.m["some_key"]++
148148
counter.Unlock()
149149

memo/memo.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ MacOS
222222
brew install rmtrash # npm install -g safe-rm; alias rm='safe-rm'
223223
224224
# 增加 terminal 光标移动速度, https://stackoverflow.com/questions/4489885/how-can-i-increase-the-cursor-speed-in-terminal
225-
#defaults write NSGlobalDomain KeyRepeat -int 1
225+
# defaults write NSGlobalDomain KeyRepeat -int 1
226226
mac: 系统设置-> 键盘 -> 修改按键重复到最快,重复前延迟最短。可以让光标在终端里移动更快
227227
228228
# 如何在文件更新之后自动刷新浏览器,需要首先 pip 安装 when-changed

0 commit comments

Comments
 (0)