Skip to content

Instantly share code, notes, and snippets.

@rhiguchi
Created February 25, 2012 13:55
Show Gist options
  • Save rhiguchi/1908613 to your computer and use it in GitHub Desktop.
Save rhiguchi/1908613 to your computer and use it in GitHub Desktop.
Scala で ReadWriteLock にローンパターンを使う ref: http://qiita.com/items/2805
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