-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to centralised loom safe locks #8371
Conversation
…8290)" (square#8367) This reverts commit 689d388.
internal object Locks { | ||
inline fun <T> Dispatcher.withLock(action: () -> T): T { | ||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } | ||
// TODO remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly temporary checks, unless we think these are cheap based on assertion enablement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do all the work to have a ReentrantLock and then forbid its use?
These checks are not fast enough to include.
https://publicobject.com/2019/11/18/kotlins-assert-is-not-like-javas-assert/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the opposite, this was a quick check to fail if we also had synchronization on the owner, not a concurrent Lock.
|
||
// TODO remove | ||
assertThreadDoesntHoldLock() | ||
// TODO can we assert we don't have the connection lock? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a good structure to handle this sort of lock hierarchy?
Catching the ones I missed
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great!
var idleCallback: Runnable? = null | ||
get() = this.withLock { field } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for follow up: should we do a property delegate so we can have syntax like this?
var idleCallback: Runnable? by lock.property(null)
(or similar)
internal object Locks { | ||
inline fun <T> Dispatcher.withLock(action: () -> T): T { | ||
contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } | ||
// TODO remove |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do all the work to have a ReentrantLock and then forbid its use?
These checks are not fast enough to include.
https://publicobject.com/2019/11/18/kotlins-assert-is-not-like-javas-assert/
Mostly #8290
But with a centralised lock definition. Draft for discussion, but possibly we could encode the rules from docs/contribute/concurrency.md, so we fail fast if we ever break them.