synchronized

inline fun <R> synchronized(lock: Any, block: () -> R): R(source)

Executes the given function block while holding the monitor of the given object lock.

Since Kotlin

1.0