0
我正在尋找大猩猩上下文來源代碼。我不明白它做了什麼同步,mutex.Lock,mutex.Unlock。當我從源代碼中移除mutex.Lock和Mutex.Unlock時,它仍在運行。什麼是golang中的同步(sync.RWMutex)
import (
"net/http"
"sync"
"time"
)
var (
mutex sync.RWMutex
data = make(map[*http.Request]map[interface{}]interface{})
datat = make(map[*http.Request]int64)
)
// Set stores a value for a given key in a given request.
func Set(r *http.Request, key, val interface{}) {
mutex.Lock()
if data[r] == nil {
data[r] = make(map[interface{}]interface{})
datat[r] = time.Now().Unix()
}
data[r][key] = val
mutex.Unlock()
}