Created
February 25, 2012 13:55
-
-
Save rhiguchi/1908613 to your computer and use it in GitHub Desktop.
Scala で ReadWriteLock にローンパターンを使う ref: http://qiita.com/items/2805
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
object LoanPatternLock { | |
import java.util.concurrent.locks.{Lock, ReadWriteLock} | |
def lockWith[A <% Lock, B](l: A)(e: => B) = { | |
l.lock() | |
try e finally l.unlock() | |
} | |
def readLockWith[A <% ReadWriteLock, B](l: A)(e: => B) = | |
lockWith(l.readLock)(e) | |
def writeLockWith[A <% ReadWriteLock, B](l: A)(e: => B) = | |
lockWith(l.writeLock)(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment