Skip to content

kawasin73/umutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

umutex

Build Status

Upgradable RWMutex implementation for Go.

Upgrade() is given priority to Lock().

How to use

import "github.com/kawasin73/umutex"

var mu umutex.UMutex

// goroutine 1
mu.RLock()

// goroutine 2
mu.RLock()

// goroutine 1 : Upgrade waits until RUnlock at goroutine 2
mu.Upgrade()

// goroutine 2 : Upgrade at several goroutine makes dead-locks and return false
mu.Upgrade() == false
mu.RUnlock()

// goroutine 1 : Upgrade succeeds
import "github.com/kawasin73/umutex"

var mu umutex.UMutex

// goroutine 1
mu.RLock()

// goroutine 2 : Lock waits until unlocked at goroutine 1
mu.Lock()

// goroutine 1 : Upgrade is given priority to Lock and success
mu.Upgrade() == true

// goroutine 1
mu.Unlock()

// goroutine 2 : Lock succeeds

API

  • RLock()
  • RUnlock()
  • Lock()
  • Unlock()
  • Upgrade() -> bool

LICENSE

MIT