Created
June 1, 2017 20:57
-
-
Save keyurgolani/ca7da0d806777e16291b6886708cf5a7 to your computer and use it in GitHub Desktop.
Locking mechanism for multithreaded code in Kotlin.
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
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