Skip to content

ooopSnake/timed_mutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

timed_mutex

go report license Maintenance PRs Welcome Ask Me Anything !

Usage

import "github.com/ooopSnake/timed_mutex"

Overview

📌 Lock()

acquire a lock,block until lock obtained

📌 UnLock()

release lock

📌 TryLock() (locked bool)

try acquire a lock, true if lock obtained otherwise return false immediately.

📌 TryLockTimeout(t time.Duration) (locked bool)

try acquire a lock in specified duration, true if lock obtained.

return false if the mutex still unavailable until specified time point has been reached.

Getting Started

init lock 😏

locker := timed_mutex.New()

unlock 😐

locker.UnLock()

direct lock 😐

locker.Lock()

trylock 😎

locked :=  locker.TryLock()

trylock with timeout 😎

locked := locker.TryLockTimeout(time.Second*5)

License

Released under the MIT License