Last active
November 29, 2019 01:23
-
-
Save kawasin73/9703ba6ba1ab872ba95b2bd9f5c4f26b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
property | |
w int | |
r int | |
mu sync.Mutex | |
rwmu sync.RWMutex | |
rlock | |
mu.lock | |
r++ | |
if w == 0 | |
rwmu.rlock | |
mu.unlock | |
else | |
mu.unlock | |
rwmu.rlock | |
tryrlock | |
mu.lock | |
if w > 0 | |
mu.unlock | |
return false | |
else | |
r++ | |
rwmu.rlock | |
mu.unlock | |
lock | |
mu.lock | |
w++ | |
if r > 0 || w > 1 | |
mu.unlock | |
rwmu.lock | |
else | |
rwmu.lock | |
mu.unlock | |
trylock | |
mu.lock | |
if r > 0 || w > 0 | |
mu.unlock | |
return false | |
else | |
w++ | |
rwmu.lock | |
mu.unlock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment