你不需要另一個互斥鎖,如果你只是在 int* 類型上操作,你可以一起拋棄互斥鎖并使用 atomic.*type shared struct { sharedCounter int64 // member shared between multiple goroutines, protected by mutex exclusiveCounter int64 // member exclusive of one goroutine -- is mutex needed?}func (s *shared) readCounter() int64 { return atomic.LoadInt64(&s.sharedCounter)}func (s *shared) setCounter(i int64) { atomic.StoreInt64(&s.sharedCounter, i)}playground
Go http Request 將 POST 檢測為 GET
寶慕林4294392
2021-12-07 16:45:15