Skip to content

Instantly share code, notes, and snippets.

@keyurgolani
Created June 1, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keyurgolani/ca7da0d806777e16291b6886708cf5a7 to your computer and use it in GitHub Desktop.
Save keyurgolani/ca7da0d806777e16291b6886708cf5a7 to your computer and use it in GitHub Desktop.
Locking mechanism for multithreaded code in Kotlin.
data class Lock<T: Any>(private val obj: T) {
public fun acquire(func: (T) -> Unit) = synchronized (obj) {
func(obj)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment