Created
May 20, 2012 13:32
-
-
Save seadowg/2758143 to your computer and use it in GitHub Desktop.
Semaphore implementation with Scala's synchronized
This file contains hidden or 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
class Semaphore(private var count : Int) { | |
def p() { | |
synchronized { | |
while (count < 1) {} | |
count = count - 1 | |
} | |
} | |
def v() { | |
synchronized { | |
count = count + 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment