久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      golang 什么時(shí)候用鎖

      golang 什么時(shí)候用鎖

      Go語言包中的 sync 包提供了兩種鎖類型:sync.Mutex 和 sync.RWMutex。 (推薦學(xué)習(xí):go)

      Mutex 是最簡單的一種鎖類型,同時(shí)也比較暴力,當(dāng)一個(gè) goroutine 獲得了 Mutex 后,其他 goroutine 就只能乖乖等到這個(gè) goroutine 釋放該 Mutex。

      RWMutex 相對(duì)友好些,是經(jīng)典的單寫多讀模型。在讀鎖占用的情況下,會(huì)阻止寫,但不阻止讀,也就是多個(gè) goroutine 可同時(shí)獲取讀鎖(調(diào)用 RLock() 方法;

      而寫鎖(調(diào)用 Lock() 方法)會(huì)阻止任何其他 goroutine(無論讀和寫)進(jìn)來,整個(gè)鎖相當(dāng)于由該 goroutine 獨(dú)占。從 RWMutex 的實(shí)現(xiàn)看,RWMutex 類型其實(shí)組合了 Mutex:

      type RWMutex struct {     w Mutex     writerSem uint32     readerSem uint32     readerCount int32     readerWait int32 }

      sync.mutex 加鎖后禁止其他地方讀或?qū)懀@個(gè)適用于可能出現(xiàn)的在不同go協(xié)程中修改同一個(gè)數(shù)據(jù)

      sync.rwmutex 的lock 和 unlock 的使用和sync.mutex類似

      sync.rwmutex 的rlock和runlock的使用適用于要讀取數(shù)據(jù),防止在讀取的同時(shí)可能出現(xiàn)的別的地方寫入,而導(dǎo)致的讀取失敗

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)