safeWrite

inline fun <T> ReentrantReadWriteLock.safeWrite(lambda: () -> T): T

Execute the given lambda while holding the supplied ReentrantReadWriteLock's write lock. This is the correct alternative to the brokenwrite supplied by the Kotlin library, which non-atomically attempts to upgrade a read lock into a write lock by first dropping all extant holds of the read lock (!).

Receiver

The ReentrantReadWriteLock.

Return

The result of evaluating the supplied lambda.

Author

Todd L Smith

Parameters

lambda

The action to perform while holding the write lock.